On Tuesday 23 May 2006 20:04, medhat wrote: > 1. I would like to generate the 'upload_to' parameter of the > FileField based on the value of another field in my model. > > example: > > === > class File(models.Model): > title = models.CharField(maxlength=50) > project = models.ForeignKey(Project) > document = models.FileField(upload_to='files/' + self.title + > '/',blank=True,null=True) > === > > > 2. I would like to use some value from my instance to create the Q > object passed to the 'limit_choices_to' parameter. > > example: > > === > class File(models.Model): > title = models.CharField(maxlength=50) > project = models.ForeignKey(Project) > supercedes = > models.ForeignKey('self',limit_choices_to=Q(project=self.project,blan >k=True,null=True) ===
You can't do either of these with Django -- limit_choices_to and upload_to are defined as attributes of the model, and not instances. To enable something like this, they would have to be defined as callables that take a model instance as a parameter, or something like that. However, you've still got problems with both your examples. In particular, when would those callables be called? In your examples, the behaviour of one field (and associated admin and manipulator functionality) depends on values of other instance variables, so the order in which those fields get updated will affect the outcome. Also, if the user changed the 'project', the admin would have to immediately do a round trip to the server to update the 'supercedes' options -- how would it know to do this? A work-around for the first case is to override save() and move the document to the correct folder after the model instance has been saved. Luke -- "The truth will set your teeth free." (Calvin and Hobbes) Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---