Ok, after looking through the django wiki entries for AuditTrail (http://code.djangoproject.com/wiki/AuditTrail) and DynamicModels (http://code.djangoproject.com/wiki/DynamicModels), I guess I can see that there is a potential solution there.
But I'd still appreciate any comments on the desirability of doing this, and potential alternative solutions. Thanks, Richard On Jun 17, 8:03 pm, Richard Colley <[email protected]> wrote: > I have a need to define 2 models, both with a large number of fields > in common, but where in once case these common fields are completely > optional, and in the other case they are mandatory. > > class XYZTemplate(Model): > field_a = TextField( .... blank=True) > field_b = TextField( .... blank=True) > field_c = IntegerField( .... blank=True) > # other fields unique to this class > > Notice, in the XYZTemplate, the fields from A are all optional. > > class XYZ(Model): > field_a = TextField( .... blank=False) > field_b = TextField( .... blank=False) > field_c = IntegerField( .... blank=False) > # other fields unique to this class > > But in XYZ they must be filled in. > > My purpose is to allow "templates" (gee that's a bit of an overworked > term ... I am *not* referring here to django html templates) of an > object to be partially filled in and stored in the database as an > XYZTemplate Then at a later time, many XYZ instances will be created > based on the "default" values stored in an XYZTemplate instance. > > I was thinking along the lines of an abstract model like so: > > class A(Model): > field_a = TextField( .... blank=True) > field_b = TextField( .... blank=True) > field_c = IntegerField( .... blank=True) > class Meta: > abstract=True > app_label='...' > > Then define the other classes as: > > class XYZTemplate(Model, A): > # other fields unique to this class > > class XYZ(Model, A): > # other fields unique to this class > > But how do I make the XYZ field_a, field_b, field_c have blank=False. > > Without violating DRY, is there any way I can do this in Django? Can > I fiddle with the attributes of the fields from class A in class XYZ? > Any other solutions? > > Thanks for any advice, > Richard --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

