On Jul 17, 4:08 pm, onoxo <[email protected]> wrote: > how can i access ForeignKey model attribute value in save() or > __unicode__ method? > some hint will help. > > here is my model.py: > > class PhotoSetPhotoItem(models.Model): > photo_item = models.ForeignKey('Photo', related_name='photoitem') > slug = models.SlugField(blank = True, null = True) > > def __unicode__(self): > # ----> BELOW IS THE PROBLEMATIC PART > return str(self.photo_set)+str(self.photo_item)+str > (self.photo_item.img) > > def save(self, force_insert=False, force_update=False): > if self.photo_item != None: > # ----> BELOW IS THE PROBLEMATIC PART > self.slug = str(self.photo_set)+str(self.photo_item)+str > (self.photo_item.img) > super(PhotoSetPhotoItem, self).save(force_insert, > force_update) > > class Photo(models.Model): > title_hr = models.CharField('(hr)', max_length=255) > slug = models.SlugField() > img = FileBrowseField(max_length=200, initial_directory="", ...) > > def __unicode__(self): > return self.title_hr > > def getImg(self): > return self.img > > tnx! > Vedran
What is self.photo_set supposed to be? There's no reference to any attribute called that anywhere. You haven't actually stated what the problem is. A traceback would be useful. One point: you use str within your __unicode__ method. This is a very, very bad idea. As long as you are just using ASCII characters you will be OK, but as soon as you have an accent anywhere the whole thing will die horribly. Always use unicode strings. -- DR --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

