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 [email protected].
To post to this group, send email to [email protected].
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/d85bd120-236e-4e50-a104-29675f340d28%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to