Thursday, October 31, 2013

Re: django - default value name for the ForeignKey

Thank you so much for your reply. But I am just a beginer, didn't quite understood the 'Manger' thing. Will you please be kind enough to elaborate a little more. Thank you.


On Thu, Oct 31, 2013 at 8:44 PM, Aamu Padi <aamupadi@gmail.com> wrote:

I have a model for uploading photos in an album by the users. But if the user don't want to create an album, and just upload photos, I want it to be uploaded in a default album, namely 'Default album'. So that, whenever the user uploads photo without creating a new album, the 'Default album should be updated by that photos. For that, I thought about giving a default value in the title of the Album, but I also don't want to create a new album with name 'Default album' whenever the user doesn't create a new album to upload photo. I just want to update the 'Default Album'. Please suggest me how to achieve the above mentioned. And also is it okay to just give the ForeignKey field of the User to the Album class and not the Photo class??? Thank you!

models.py:

class Album(models.Model):      title = models.CharField(max_length=200)      pub_date = models.DateTimeField(default=datetime.now)      user = models.ForeignKey(User)      class Photo(models.Model):      album = models.ForeignKey(Album)      title = models.CharField(max_length=200)      image = models.ImageField(upload_to=get_upload_file_name, blank=True)      pub_date = models.DateTimeField(default=datetime.now)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHSNPWsH%3DsVO7WJFRp2t8BZzu170-fD_ytamp-arN%2BCkEG639g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment