Your Ad Here

Thursday, January 12, 2012

Trying to use one model class as a default for another.

So I have an idea where I want to create a table where it is linked to
another where if there are default value it will pre populate the
fileds.


here is a sample model - My problem is I dont know where to start. Any
concept of idea would greatly be welcome.

In my example If you picked a existing Task in LineItems all the
fields from that task ("if they exist") would pre populate the
corresponding fields in the listitem. I'm not sure if this can be done
in the model or if it would have to be done in say the admin
controller.

Example Model -

class LineItems(models.Model):
task = models.ForeignKey('Tasks', null=True, blank=True)
description = models.CharField(max_length=200)
rate = models.DecimalField(max_digits=10,
decimal_places=2 )
qauntiy = models.DecimalField(max_digits=10,
decimal_places=2 )
tax = models.DecimalField(max_digits=10, decimal_places=2,
null=True, blank=True)
discount = models.DecimalField(max_digits=10, decimal_places=2,
null=True, blank=True)

class Tasks(models.Model):
Title = models.CharField(max_length=200)
description = models.CharField(max_length=200, null=True,
blank=True)
rate = models.DecimalField(max_digits=10, decimal_places=2,
null=True, blank=True )
qauntiy = models.DecimalField(max_digits=10, decimal_places=2,
null=True, blank=True )
tax = models.DecimalField(max_digits=10, decimal_places=2,
null=True, blank=True)
discount = models.DecimalField(max_digits=10, decimal_places=2,
null=True, blank=True)

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 comments:

Post a Comment