If you first run syncdb with the UserPic.user field unique=True, it's not 
enough just to change unique=False. You'll also need to remove the database 
unique constraint. Do you have the problem on a fresh syncdb if 
unique=False? If so, it would be helpful to include the full traceback of 
the error.

On Tuesday, November 19, 2013 4:34:35 PM UTC-5, HannesP wrote:
>
> I'm Django noob so please bear with me. I am trying to make a simple 
> gallery for usres so that they can upload pics to their profile. Here are 
> the relevant parts:
>
> models.py
>
> def get_uplaod_file_name(instance,filename):
>     return 'uploaded_files/%s_%s' % (str(time()).replace('.','_'), filename)
> class UserPic(models.Model):
>     user = models.ForeignKey(User, unique=False)
>     picfile = models.FileField(upload_to=get_uplaod_file_name)
>
>     @models.permalink
>     def get_absolute_url(self):
>         return ('view_pirate', None, {'user': self.account.user})    
>
>     def __unicode__(self):
>         return unicode(self.picfile.name) 
>
> views.py
>
> @login_requireddef list(request):
>     # Handle file upload
>     if request.method == 'POST':
>         picform = PicForm(request.POST, request.FILES)
>         if picform.is_valid():
>
>             newpic = UserPic(picfile = request.FILES['picfile'])
>             newpic = picform.save(commit=False)
>             newpic.user = request.user
>             newpic.save()
>             message = "file %s is uploaded" % newpic
>             userpics = UserPic.objects.all()
>
>             return render_to_response('userpics/listpics.html',
>                                       {'userpics': userpics, 'picform': 
> picform},
>                                       context_instance=RequestContext(request)
>     )
>
>
>     else:
>         picform = PicForm() # A empty, unbound form
>
>
>     userpics = UserPic.objects.all()
>
>
>     return render_to_response(
>         'userpics/listpics.html',
>         {'userpics': userpics, 'picform': picform},
>         context_instance=RequestContext(request)
>     )
>
> The app works fine for one image upload but the problem is that whenever a 
> user tries to upload a second image, Django gives this error:
>
> column user_id is not unique
>
> I have also tried 'unique= True on a fresh database in the model, but 
> still got stocked at this problem. Appreciate your hints. 
>
> Thanks
>

-- 
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+unsubscr...@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/9a5ac221-b8e5-4692-ac9b-cfb4e4622c9f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to