after some debugging i find that i had a bug in filebrowser app. the code from above is ok and self.photo_set is something that i forget to remove before posting. but can you tell me how should i convert to unicode?
self.slug = unicode(self.photo_set)+unicode(self.photo_item) is this ok? On Jul 19, 4:15 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Jul 17, 4:08 pm, onoxo <vedran.ko...@gmail.com> 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 django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---