auth select chooses in forms.py

Xristos Xristoou saxri89 at gmail.com
Sun Apr 9 10:20:15 EDT 2017


I have read this code in this question and look nice. but if I have user auth and I want user select only your odjects how to change that code ?for ex chooses your personal upload images.
from django.forms.widgets import Select
    class ProvinceForm(ModelForm):
        class Meta:
            CHOICES = Province.objects.all()

            model = Province
            fields = ('name',)
            widgets = {
                'name': Select(choices=( (x.id, x.name) for x in CHOICES )),
            }
my model :
class MyModel(models.Model):
    user = models.ForeignKey(User, unique=True)
    upload = models.ImageField(upload_to='images')


More information about the Python-list mailing list