Thanks for the tip. I don't think the override will work in my particular case because I don't always add the defaults. I have a check box on the form "Add default DNS Records" and I check for this in the view:
if form.is_valid(): domain = form.save(commit=True) if request.POST.__contains__('addDefaultDNS'): d = DNSRecord(domain=domain, type='NS', data='ns1.mydomain.com', aux=0, ttl=7200) new_d = d.save() d = DNSRecord(domain=domain, type='NS', data='ns2.mydomain.com', aux=0, ttl=7200) new_d = d.save() Two of the ideas I have are: 1. Add a new model to the app, defaultDNSRecords, then copy the defaults during the save. This has the benefit that the defaults can be edited in the app. 2. add some form of dict to settings.py and loop through it. Is there any standard for doing this sort of thing? Paddy On Oct 1, 6:59 pm, "Jonathan Buchanan" <[EMAIL PROTECTED]> wrote: > On 10/1/07, Paddy Joy <[EMAIL PROTECTED]> wrote: > > > > > > > I have a many to one relationship between domain and DNSRecord. When > > adding a domain I need to add some default DNSRecords. I do this after > > saving the domain using the following code. > > > domain = form.save(commit=True) > > > d = DNSRecord(domain=domain, type='NS', data='ns1.mydomain.com', > > aux=0, ttl=7200) > > new_d = d.save() > > > d = DNSRecord(domain=domain, type='NS', data='ns2.mydomain.com', > > aux=0, ttl=7200) > > new_d = d.save() > > > d = DNSRecord(domain=domain, type='NS', data='ns3.mydomain.com', > > aux=0, ttl=7200) > > new_d = d.save() > > > d = DNSRecord(domain=domain, type='NS', data='ns4.mydomain.com', > > aux=0, ttl=7200) > > new_d = d.save() > > > It works but it's not very nice because the default records are hard > > coded into the view. Does anyone have any suggestions for a better > > approach? > > > Paddy > > I would override the Domain model's save method for that. Something like: > > class Domain(models.Model): > # ... > > def save(self, **kwargs): > is_new = not self.id > super(Domain, self).save(**kwargs) > if is_new: > for i in range(1, 5): > self.dns_records.create(data='ns%s.mydomain.com' % i, > type='NS',aux=0, ttl=7200) > > class DNSRecord(models.Model): > # ... > domain = models.ForeignKey(Domain, related_name='dns_records') > # ... > > Jonathan. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---