Re: Thoughts on many-to-many relationship

2009-07-31 Thread Wyley
Hi Prabhu, You are correct about how to fix the error you're seeing, but I think you're confused about why you're seeing it. As with all relationships, an object in a many-to-many relationship must have a primary key value before you can point a foreign key value at it from another table. When

Choices on CharField suppresses non-choice data in admin

2009-04-22 Thread Wyley
Hello all, I'm wondering if the following behavior is a feature, a bug, or a coding error on my part: when I define a model with a CharField that has choices, if I later save an instance of the model with a value for that field which is not one of the choices, the value does not display in the a

Selecting a parent in admin for a child model?

2009-03-19 Thread Wyley
Hi all, I have a quick question about editing instances of child models in the admin interface. I have a couple of models which derive from a (non- abstract) parent model, thusly: class Contact(models.Model): first_name = models.CharField(...) last_name = models.CharField(...) # etc

Dynamically-added fields in a ModelForm don't appear in admin?

2009-03-13 Thread Wyley
Hello all, I am trying to create a ModelForm subclass to customize the admin interface for one of my models. In particular, I am attempting to add a field to the ModelForm dynamically in its __init__ method (per advice found here: http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/). I would

Re: ForeignKey with null=True gives 'may not be NULL' error

2008-01-24 Thread Wyley
> No, it is not the case that null=True is disallowed for FKs, but it > probably should be. I've just been reading the code in django.db.models.fields.related, and there's a pretty clear indication that the Django developers explicitly wanted ForeignKeys to be nullable. In the RelatedManager cla

Re: ForeignKey with null=True gives 'may not be NULL' error

2008-01-23 Thread Wyley
Michael, Thanks for your reply! > Many databases will allow a constraint with a foreign key to be deferrable > and initially deferred so that you don't have to disable the relationship > to load data. Can you say a bit more about this? I'm by no means an expert on databases; I'm not quite sure

Re: ForeignKey with null=True gives 'may not be NULL' error

2008-01-23 Thread Wyley
Update: in the SQL for the Title table, CREATE TABLE "core_title" ( ... "supplier_id" integer NULL, ); Two things to note: 1. the SQL explicitly allows the supplier field to be NULL 2. the 'REFERENCES "core_contact" ("id") clause is conspicuous

ForeignKey with null=True gives 'may not be NULL' error

2008-01-23 Thread Wyley
Hello all, I have a model with a ForeignKey field that sets null=True: class Title(models.Model): #... supplier = models.ForeignKey(Contact, verbose_name='Supplier', null=True) ...but when I try to save an instance without a supplier: >>> t = Title() >>> t.save() [complete Traceback be

Mixins and non-database fields on instances

2008-01-20 Thread Wyley
Hello all, I'm currently using a mixin class to contribute a few extra fields to my models, to keep track of some metadata on instances (for example, an update_mode attribute that specifies whether data should replace all fields or only non-empty ones in the database when the instance is saved).

Re: Dealing with related objects in a generic way

2007-12-10 Thread Wyley
> You're not missing anything - traversing _meta.fields et al is pretty > much how you would need to do what you are describing. Thanks, that's what I needed to know! Richard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

Dealing with related objects in a generic way

2007-12-10 Thread Wyley
Hello all, I am new to Django and quite excited to be using it. I am attempting to write some generic import and export methods, and I keep running into a conceptual hurdle that has to do with related objects:how can I recursively follow database relations in a way that's not model- dependen