How to ensure model instance has at least one relater

2007-01-11 Thread Crispin Bennett
Hi, I have a pair of models A and B, where B has a foreign key pointing to A. I want to ensure that instances of A have at least one (B) referrer. The obvious way (to me, still learning python and Django) was to override A's 'save' method, checking for the existence of at least one referring B

Re: Re: Templates for unknown object types

2006-12-18 Thread Crispin Bennett
> > It's not a particularly bad idea; having an object carry with it > standardized information which tells you what template to use to > display it would be pretty easy (assuming, of course, that you have > the ability to lay out the model classes to support that). > Fortunately my models make

Re: Templates for unknown object types

2006-12-18 Thread Crispin Bennett
On 12/19/06, James Bennett <[EMAIL PROTECTED]> wrote: > > Even if the types aren't known in advance, it's possible to make some > educated guesses; most classes will, for example, have a __str__ > method which will allow them to intelligently print themselves as > strings. > > If you know what

Templates for unknown object types

2006-12-18 Thread Crispin Bennett
Is there a natural way in Django to write a template that can display the details of objects of various types, where the types aren't necessarily known in advance? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups

Re: Strange SQL inconsistency with OneToOne fields

2006-12-16 Thread Crispin Bennett
One correction: One 'child' class (ie. with a OneToOneField) does always keep the reference to the base class in it's pk column. A couple of additions: - the OneToOneField is obviously partially working, as even when the reference is dnot there, the standard 'id' field name is correctly

Strange SQL inconsistency with OneToOne fields

2006-12-16 Thread Crispin Bennett
I have a models.py with several model classes referencing a 'base' model class using OneToOne fields. The CREATE statement displayed by manage.py sqlall is weirdly inconsistent -- sometimes the id columns of the 'child' model classes contain a REFERENCES clause (ie. to the 'base' class),

Re: Model inheritance

2006-12-14 Thread Crispin Bennett
On 12/14/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: > > Django does have the ability to do a sort of model inheritance, using > OneToOneFields. This establishes a 1-1 relationship between a base > class and a child class. I assume it would be possible to get at child instances via some

Re: Model inheritance

2006-12-14 Thread Crispin Bennett
On 12/14/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: > > > Yes and No. > > Django does have the ability to do a sort of model inheritance, using > OneToOneFields. This establishes a 1-1 relationship between a base > class and a child class. For example: > > class Base(Model): >name =

Model inheritance

2006-12-13 Thread Crispin Bennett
My first experiment with Django is a kind of wiki that involves being able to add a variety of different types of pages, each with their own set of fields. The obvious way to do this would be to create a base model page class which various page types inherit. But I can't imagine how the Django