Search Results

Search found 5 results on 1 pages for 'unclaimedbaggage'.

Page 1/1 | 1 

  • Testing Django Inline ModelForms: How to arrange POST data?

    - by unclaimedbaggage
    Hi folks, I have a Django 'add business' view which adds a new business with an inline 'business_contact' form. The form works fine, but I'm wondering how to write up the unit test - specifically, the 'postdata' to send to self.client.post(settings.BUSINESS_ADD_URL, postdata) I've inspected the fields in my browser and tried adding post data with corresponding names, but I still get a 'ManagementForm data is missing or has been tampered with' error when run. Anyone know of any resources for figuring out how to post inline data? Relevant models, views & forms below if it helps. Lotsa thanks. MODEL: class Contact(models.Model): """ Contact details for the representatives of each business """ first_name = models.CharField(max_length=200) surname = models.CharField(max_length=200) business = models.ForeignKey('Business') slug = models.SlugField(max_length=150, unique=True, help_text=settings.SLUG_HELPER_TEXT) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) phone = models.CharField(max_length=100, null=True, blank=True) mobile_phone = models.CharField(max_length=100, null=True, blank=True) email = models.EmailField(null=True) deleted = models.BooleanField(default=False) class Meta: db_table='business_contact' def __unicode__(self): return '%s %s' % (self.first_name, self.surname) @models.permalink def get_absolute_url(self): return('business_contact', (), {'contact_slug': self.slug }) class Business(models.Model): """ The business clients who you are selling products/services to """ business = models.CharField(max_length=255, unique=True) slug = models.SlugField(max_length=100, unique=True, help_text=settings.SLUG_HELPER_TEXT) description = models.TextField(null=True, blank=True) primary_contact = models.ForeignKey('Contact', null=True, blank=True, related_name='primary_contact') business_type = models.ForeignKey('BusinessType') deleted = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) address_1 = models.CharField(max_length=255, null=True, blank=True) address_2 = models.CharField(max_length=255, null=True, blank=True) suburb = models.CharField(max_length=255, null=True, blank=True) city = models.CharField(max_length=255, null=True, blank=True) state = models.CharField(max_length=255, null=True, blank=True) country = models.CharField(max_length=255, null=True, blank=True) phone = models.CharField(max_length=40, null=True, blank=True) website = models.URLField(null=True, blank=True) class Meta: db_table = 'business' def __unicode__(self): return self.business def get_absolute_url(self): return '%s%s/' % (settings.BUSINESS_URL, self.slug) VIEWS: class Contact(models.Model): """ Contact details for the representatives of each business """ first_name = models.CharField(max_length=200) surname = models.CharField(max_length=200) business = models.ForeignKey('Business') slug = models.SlugField(max_length=150, unique=True, help_text=settings.SLUG_HELPER_TEXT) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) phone = models.CharField(max_length=100, null=True, blank=True) mobile_phone = models.CharField(max_length=100, null=True, blank=True) email = models.EmailField(null=True) deleted = models.BooleanField(default=False) class Meta: db_table='business_contact' def __unicode__(self): return '%s %s' % (self.first_name, self.surname) @models.permalink def get_absolute_url(self): return('business_contact', (), {'contact_slug': self.slug }) class Business(models.Model): """ The business clients who you are selling products/services to """ business = models.CharField(max_length=255, unique=True) slug = models.SlugField(max_length=100, unique=True, help_text=settings.SLUG_HELPER_TEXT) description = models.TextField(null=True, blank=True) primary_contact = models.ForeignKey('Contact', null=True, blank=True, related_name='primary_contact') business_type = models.ForeignKey('BusinessType') deleted = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) address_1 = models.CharField(max_length=255, null=True, blank=True) address_2 = models.CharField(max_length=255, null=True, blank=True) suburb = models.CharField(max_length=255, null=True, blank=True) city = models.CharField(max_length=255, null=True, blank=True) state = models.CharField(max_length=255, null=True, blank=True) country = models.CharField(max_length=255, null=True, blank=True) phone = models.CharField(max_length=40, null=True, blank=True) website = models.URLField(null=True, blank=True) class Meta: db_table = 'business' def __unicode__(self): return self.business def get_absolute_url(self): return '%s%s/' % (settings.BUSINESS_URL, self.slug) FORMS: class AddBusinessForm(ModelForm): class Meta: model = Business exclude = ['deleted','primary_contact',] class ContactForm(ModelForm): class Meta: model = Contact exclude = ['deleted',] AddBusinessFormSet = inlineformset_factory(Business, Contact, can_delete=False, extra=1, form=AddBusinessForm, )

    Read the article

  • Django unit testing: South-migrated DB works in MySQL, throws duplicate PK error in PostGreSQL. Am I

    - by unclaimedbaggage
    Hi folks, (Worth starting off with a disclaimer: I'm very new to PostGreSQL) I have a django site which involves a standard app/tests.py testing file. If I migrate the DB to MySQL (through South),, the tests all pass. However in PostGresQL, I'm getting the following error: IntegrityError: duplicate key value violates unique constraint "business_contact_pkey" Note this happens while unit testing only - the actual page runs fine in both MySQL & PostGresql. Really having a heckuva time figuring this one out. Anyone have ideas? Below are the Postgresql "\d business_contact" & offending tests.py method if they help. No changes made to either DB except the (same) South migrations Thanks first_name | character varying(200) | not null mobile_phone | character varying(100) | surname | character varying(200) | not null business_id | integer | not null created | timestamp with time zone | not null deleted | boolean | not null default false updated | timestamp with time zone | not null slug | character varying(150) | not null phone | character varying(100) | email | character varying(75) | id | integer | not null default nextval('business_contact_id_seq'::regclass) Indexes: "business_contact_pkey" PRIMARY KEY, btree (id) "business_contact_slug_key" UNIQUE, btree (slug) "business_contact_business_id" btree (business_id) Foreign-key constraints: "business_id_refs_id_772cc1b7b40f4b36" FOREIGN KEY (business_id) REFERENCES business(id) DEFERRABLE INITIALLY DEFERRED Referenced by: TABLE "business" CONSTRAINT "primary_contact_id_refs_id_dfaf59c4041c850" FOREIGN KEY (primary_contact_id) REFERENCES business_contact(id) DEFERRABLE INITIALLY DEFERRED TEST DEF: def test_add_business_contact(self): """ Add a business contact """ contact_slug = 'test-new-contact-added-new-adf' business_id = 1 business = Business.objects.get(id=business_id) postdata = { 'first_name': 'Test', 'surname': 'User', 'business': '1', 'slug': contact_slug, 'email': '[email protected]', 'phone': '12345678', 'mobile_phone': '9823452', 'business': 1, 'business_id': 1, } #Test to ensure contacts that should not exist are not returned contact_not_exists = Contact.objects.filter(slug=contact_slug) self.assertFalse(contact_not_exists) #Add the contact and ensure it is present in the DB afterwards """ contact_add_url = '%s%s/contact/add/' % (settings.BUSINESS_URL, business.slug) self.client.post(contact_add_url, postdata) added_contact = Contact.objects.filter(slug=contact_slug) print added_contact try: self.assertTrue(added_contact) except: formset = ContactForm(postdata) print formset.errors self.assertFalse(True, "Contact not found in the database - most likely, the post values in the test didn't validate against the form")

    Read the article

  • Django: Filtering datetime field by *only* the year value?

    - by unclaimedbaggage
    Hi folks, I'm trying to spit out a django page which lists all entries by the year they were created. So, for example: 2010: Note 4 Note 5 Note 6 2009: Note 1 Note 2 Note 3 It's proving more difficult than I would have expected. The model from which the data comes is below: class Note(models.Model): business = models.ForeignKey(Business) note = models.TextField() created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) class Meta: db_table = 'client_note' @property def note_year(self): return self.created.strftime('%Y') def __unicode__(self): return '%s' % self.note I've tried a few different ways, but seem to run into hurdles down every path. I'm guessing an effective 'group by' method would do the trick (PostGres DB Backend), but I can't seem to find any Django functionality that supports it. I tried getting individual years from the database but I struggled to find a way of filtering datetime fields by just the year value. Finally, I tried adding the note_year @property but because it's derived, I can't filter those values. Any suggestions for an elegant way to do this? I figure it should be pretty straightforward, but I'm having a heckuva time with it. Any ideas much appreciated.

    Read the article

  • Iterating dictionary indexes in django templates

    - by unclaimedbaggage
    Hi folks...I have a dictionary with embedded objects, which looks something like this: notes = { 2009: [<Note: Test note>, <Note: Another test note>], 2010: [<Note: Third test note>, <Note: Fourth test note>], } I'm trying to access each of the note objects inside a django template, and having a helluva time navigating to them. In short, I'm not sure how to extract by index in django templating. Current template code is: <h3>Notes</h3> {% for year in notes %} {{ year }} # Works fine {% for note in notes.year %} {{ note }} # Returns blank {% endfor %} {% endfor %} If I replace {% for note in notes.year %} with {% for note in notes.2010 %} things work fine, but I need that '2010' to be dynamic. Any suggestions much appreciated.

    Read the article

  • Foreign key on table A --> B, AND foreign key on table B --> A. How is this done?

    - by unclaimedbaggage
    Hi, I have two tables - 'business' and 'business_contacts'. The business_contact table has a many-to-one relationship with the business table. Furthermore, each business has a 'primary contact' field - which I'd assume is a one-to-many relationship with the business_contacts table. The problem, of course, is that this creates a catch-22 for data insertion. Since neither field can be null, I can't insert a business_contact until I have a corresponding business, but I can't insert a business until I have a corresponding business_contact. If anyone could help me get my head around how mutual one-to-many relationships are supposed to be dealt with I'd be most appreciative. (Project being done in MySQL if it makes any difference)

    Read the article

1