Re: FieldError at /ajouter_centre Cannot resolve keyword 'name' into field. Choices are: categorie, centredeformation, date_de_crea, id

2023-09-26 Thread Baye SALIOU DIAW
J'ai finalement résolu le problème. Merci bien!! 

Le lundi 25 septembre 2023 à 20:35:25 UTC, Muhammed Lawal a écrit :

> Have you confirmed there is a 'name' field in your CentreCategorie and 
> Region models? 
>
> On Mon, 25 Sep 2023, 5:44 p.m. Baye SALIOU DIAW,  
> wrote:
>
>> def ajouterCentre(request):
>> form = FormCentre()
>> regions = Region.objects.all()
>> centrecategories = CentreCategorie.objects.all()
>> if request.method == 'POST':
>>
>> 
>> categorie_name = request.POST.get('categorie')
>> categorie, created = CentreCategorie.objects.get_or_create(name=
>> categorie_name)
>>
>> region_name = request.POST.get('region')
>> region, created = Region.objects.get_or_create(name=region_name)
>> 
>> CentreDeFormation.objects.create(
>> categorie=request.categorie,
>> region = region,
>> nom = request.POST.get('nom'),
>> description = request.POST.get('description'),
>> adresse = request.POST.get('adresse'),
>> telephone = request.POST.get('telephone'),
>> )
>>
>> return redirect('home')
>>
>>
>> context = {
>> 'form': form, 
>> 'regions': regions, 
>> 'centrecategories': centrecategories,
>> }
>> return render(request, 'blog/ajoutercentre.html', context)
>>
>> -- 
>>
> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/8a202205-cf75-4445-9642-e995fec56833n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/84da2aca-062f-4c10-9f7f-4bdf3e48c0ffn%40googlegroups.com.


Re: FieldError at /ajouter_centre Cannot resolve keyword 'name' into field. Choices are: categorie, centredeformation, date_de_crea, id

2023-09-25 Thread Muhammed Lawal
Have you confirmed there is a 'name' field in your CentreCategorie and
Region models?

On Mon, 25 Sep 2023, 5:44 p.m. Baye SALIOU DIAW, <
bayesalioudiawt...@gmail.com> wrote:

> def ajouterCentre(request):
> form = FormCentre()
> regions = Region.objects.all()
> centrecategories = CentreCategorie.objects.all()
> if request.method == 'POST':
>
>
> categorie_name = request.POST.get('categorie')
> categorie, created = CentreCategorie.objects.get_or_create(name=
> categorie_name)
>
> region_name = request.POST.get('region')
> region, created = Region.objects.get_or_create(name=region_name)
>
> CentreDeFormation.objects.create(
> categorie=request.categorie,
> region = region,
> nom = request.POST.get('nom'),
> description = request.POST.get('description'),
> adresse = request.POST.get('adresse'),
> telephone = request.POST.get('telephone'),
> )
>
> return redirect('home')
>
>
> context = {
> 'form': form,
> 'regions': regions,
> 'centrecategories': centrecategories,
> }
> return render(request, 'blog/ajoutercentre.html', context)
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8a202205-cf75-4445-9642-e995fec56833n%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOzVPC_26jEEARrqmZ%3Dt%2BsLc7LQhJejyXykiNvW%2BBZLGQ%2BQH7A%40mail.gmail.com.


Re: FieldError at /ajouter_centre Cannot resolve keyword 'name' into field. Choices are: categorie, centredeformation, date_de_crea, id

2023-09-25 Thread Dino P.Russe
Si tu pouvais aussi envoyer le code du modèle et du formulaire,  je pense
bien que ton problème sera très rapidement

Le lun. 25 sept. 2023 à 19:44, Baye SALIOU DIAW <
bayesalioudiawt...@gmail.com> a écrit :

> def ajouterCentre(request):
> form = FormCentre()
> regions = Region.objects.all()
> centrecategories = CentreCategorie.objects.all()
> if request.method == 'POST':
>
>
> categorie_name = request.POST.get('categorie')
> categorie, created = CentreCategorie.objects.get_or_create(name=
> categorie_name)
>
> region_name = request.POST.get('region')
> region, created = Region.objects.get_or_create(name=region_name)
>
> CentreDeFormation.objects.create(
> categorie=request.categorie,
> region = region,
> nom = request.POST.get('nom'),
> description = request.POST.get('description'),
> adresse = request.POST.get('adresse'),
> telephone = request.POST.get('telephone'),
> )
>
> return redirect('home')
>
>
> context = {
> 'form': form,
> 'regions': regions,
> 'centrecategories': centrecategories,
> }
> return render(request, 'blog/ajoutercentre.html', context)
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8a202205-cf75-4445-9642-e995fec56833n%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC3RP-CV6qay3-QZXUY0%2BROZ9ALdVW3n3ZV5ky4D%2Bz9xJenm9Q%40mail.gmail.com.


FieldError at /ajouter_centre Cannot resolve keyword 'name' into field. Choices are: categorie, centredeformation, date_de_crea, id

2023-09-25 Thread Baye SALIOU DIAW
def ajouterCentre(request):
form = FormCentre()
regions = Region.objects.all()
centrecategories = CentreCategorie.objects.all()
if request.method == 'POST':


categorie_name = request.POST.get('categorie')
categorie, created = CentreCategorie.objects.get_or_create(name=
categorie_name)

region_name = request.POST.get('region')
region, created = Region.objects.get_or_create(name=region_name)

CentreDeFormation.objects.create(
categorie=request.categorie,
region = region,
nom = request.POST.get('nom'),
description = request.POST.get('description'),
adresse = request.POST.get('adresse'),
telephone = request.POST.get('telephone'),
)

return redirect('home')


context = {
'form': form, 
'regions': regions, 
'centrecategories': centrecategories,
}
return render(request, 'blog/ajoutercentre.html', context)

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8a202205-cf75-4445-9642-e995fec56833n%40googlegroups.com.


Re: Django Resolve Choices Class

2023-08-31 Thread Sebastian Jung
Thank you it is working. Wonderful

Andréas Kühne  schrieb am Do., 31. Aug. 2023,
20:03:

> If you want the string instead of the value, you just use:
> entity.get_gender_display()
>
> Django automatically adds these "magic methods" when you have fields that
> have choices.
>
> You can see this in the documentation:
> https://docs.djangoproject.com/en/4.2/ref/models/fields/#choices
>
> Regards,
>
> Andréas
>
>
> Den ons 30 aug. 2023 kl 22:11 skrev sebasti...@gmail.com <
> sebastian.ju...@gmail.com>:
>
>> I have in my
>>
>> model.py:
>>
>> class GendersChoices(models.IntegerChoices):
>> M = 0, _('Male')
>> F = 1, _('Female')
>> N = 2, _('Gender Neutral')
>>
>> class Address(models.Model):
>> gender = models.PositiveSmallIntegerField(choices=GendersChoices.choices,
>> blank=True, default=GendersChoices.F, null=True,verbose_name=_('Gender'))
>>
>> Now i have a entity from Address and when i make entity.gender i get a
>> number from database. But i want when in entity are insert 2 then i want to
>> get _('Gender Neutral') instead of 2
>>
>> How i can do that?
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/53c122e7-0448-4d67-9cd4-ce11ffa2ef5cn%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/53c122e7-0448-4d67-9cd4-ce11ffa2ef5cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK4qSCcCrg-VtCdJDFRicqY0WpvNw28SMRR3tAzvaUro69gurw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCcCrg-VtCdJDFRicqY0WpvNw28SMRR3tAzvaUro69gurw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mxk8AJtfxZFHSTsiDr1kaW7FfC5%2BK1Lo%3DYU%3D9TrTSXiGQ%40mail.gmail.com.


Re: Django Resolve Choices Class

2023-08-31 Thread Andréas Kühne
If you want the string instead of the value, you just use:
entity.get_gender_display()

Django automatically adds these "magic methods" when you have fields that
have choices.

You can see this in the documentation:
https://docs.djangoproject.com/en/4.2/ref/models/fields/#choices

Regards,

Andréas


Den ons 30 aug. 2023 kl 22:11 skrev sebasti...@gmail.com <
sebastian.ju...@gmail.com>:

> I have in my
>
> model.py:
>
> class GendersChoices(models.IntegerChoices):
> M = 0, _('Male')
> F = 1, _('Female')
> N = 2, _('Gender Neutral')
>
> class Address(models.Model):
> gender = models.PositiveSmallIntegerField(choices=GendersChoices.choices,
> blank=True, default=GendersChoices.F, null=True,verbose_name=_('Gender'))
>
> Now i have a entity from Address and when i make entity.gender i get a
> number from database. But i want when in entity are insert 2 then i want to
> get _('Gender Neutral') instead of 2
>
> How i can do that?
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/53c122e7-0448-4d67-9cd4-ce11ffa2ef5cn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/53c122e7-0448-4d67-9cd4-ce11ffa2ef5cn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCcCrg-VtCdJDFRicqY0WpvNw28SMRR3tAzvaUro69gurw%40mail.gmail.com.


Django Resolve Choices Class

2023-08-30 Thread sebasti...@gmail.com
I have in my 

model.py:

class GendersChoices(models.IntegerChoices):
M = 0, _('Male')
F = 1, _('Female')
N = 2, _('Gender Neutral')

class Address(models.Model):
gender = models.PositiveSmallIntegerField(choices=GendersChoices.choices, 
blank=True, default=GendersChoices.F, null=True,verbose_name=_('Gender'))

Now i have a entity from Address and when i make entity.gender i get a 
number from database. But i want when in entity are insert 2 then i want to 
get _('Gender Neutral') instead of 2 

How i can do that?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53c122e7-0448-4d67-9cd4-ce11ffa2ef5cn%40googlegroups.com.


Don't pass a "set" object in the choices argument for a model field

2023-03-07 Thread Tj Johnson
I just ran into this, a field will accept a "set" object for the choices 
argument, however since set objects are unordered, it's possible that a new 
migration will be created every single time makemigrations is run.

debugging this was a matter of noticing that the developer used curly 
braces instead of parentheses or brackets, it could have been very sticky.  
Wondering if this should raise a TypeError


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b1364f4-8c06-49b3-87c6-e9073ddb1e3en%40googlegroups.com.


Re: How to use choices in model field

2022-11-03 Thread Aaryan R Soni
Thanks, that worked, Thanks for your help

On Wed, Nov 2, 2022, 9:57 PM Julio Cojom  wrote:

> When you change the status to Verified, you are only changing the object
> instance in memory, to save it to the database, you need to call the method
> save.
>
> verification.save() at the end should make it work
>
> El El mié, 2 de nov. de 2022 a la(s) 10:23, Aaryan R Soni <
> aaryanrson...@gnu.ac.in> escribió:
>
>> Okay, but still the problem is that how do I set the value of status
>> field, as I have written in the code, verification.status = 'Verified' it
>> is not giving any error but it is not working either
>>
>> On Wed, Nov 2, 2022, 9:51 PM kateregga julius 
>> wrote:
>>
>>> Don't use square blackest [ ]
>>>
>>> status_choices=(('Unverified','Unverified'),('Verified','Verified'))
>>>
>>> On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni 
>>> wrote:
>>>
>>>> Hey guys, i am facing some issues using choices in models.CharField. I
>>>> am creating a model which has username and status, where status is my
>>>> choice field. it has 2 values, 'Unverified' and 'Verified'.
>>>>
>>>> class user_stutus(models.Model):
>>>> status_choices=[('Unverified','Unverified'),('Verified','Verified'
>>>> )]
>>>> uname=models.OneToOneField(User,on_delete=models.CASCADE)
>>>> status=models.CharField(max_length=11,choices=status_choices
>>>> ,default='Unverified')
>>>>
>>>> def verifyCode(request):
>>>> global errors,session
>>>> if request.method == 'POST':
>>>> code = request.POST['code']
>>>> user=User.objects.get(email=session['email'])
>>>> print('user',user)
>>>> print('request',session['email'])
>>>> if session['code'] != code:
>>>> errors['code'] = 'Verification code did not match!'
>>>> return redirect('/user/user-verify/')
>>>> verification = user_stutus.objects.get(username=user)
>>>>
>>>> *verification.status = 'Verified'#here i am changing its value and
>>>> facing the issue.*
>>>> return redirect('/user/user-login/')
>>>>
>>>> can someone give me any solution for this?
>>>> Thank you!
>>>>
>>>>
>>>>
>>>> *DISCLAIMER*
>>>>
>>>> Any views or opinions presented in this email are solely those of the
>>>> author and do not necessarily represent those of the Ganpat University.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *DISCLAIMER*
>>>>
>>>> Any views or opinions presented in this email are solely those of the
>>>> author and do not necessarily represent those of the Ganpat University.
>>>>
>>>>
>>>>
>>>> --
>>>> 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 view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>>
>> *DISCLAIMER*
>>
>> Any views or opinions presented in this email are solely those of 

Re: How to use choices in model field

2022-11-02 Thread kateregga julius
Follow exactly what he has told you

On Wed, Nov 2, 2022, 7:27 PM Julio Cojom  wrote:

> When you change the status to Verified, you are only changing the object
> instance in memory, to save it to the database, you need to call the method
> save.
>
> verification.save() at the end should make it work
>
> El El mié, 2 de nov. de 2022 a la(s) 10:23, Aaryan R Soni <
> aaryanrson...@gnu.ac.in> escribió:
>
>> Okay, but still the problem is that how do I set the value of status
>> field, as I have written in the code, verification.status = 'Verified' it
>> is not giving any error but it is not working either
>>
>> On Wed, Nov 2, 2022, 9:51 PM kateregga julius 
>> wrote:
>>
>>> Don't use square blackest [ ]
>>>
>>> status_choices=(('Unverified','Unverified'),('Verified','Verified'))
>>>
>>> On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni 
>>> wrote:
>>>
>>>> Hey guys, i am facing some issues using choices in models.CharField. I
>>>> am creating a model which has username and status, where status is my
>>>> choice field. it has 2 values, 'Unverified' and 'Verified'.
>>>>
>>>> class user_stutus(models.Model):
>>>> status_choices=[('Unverified','Unverified'),('Verified','Verified'
>>>> )]
>>>> uname=models.OneToOneField(User,on_delete=models.CASCADE)
>>>> status=models.CharField(max_length=11,choices=status_choices
>>>> ,default='Unverified')
>>>>
>>>> def verifyCode(request):
>>>> global errors,session
>>>> if request.method == 'POST':
>>>> code = request.POST['code']
>>>> user=User.objects.get(email=session['email'])
>>>> print('user',user)
>>>> print('request',session['email'])
>>>> if session['code'] != code:
>>>> errors['code'] = 'Verification code did not match!'
>>>> return redirect('/user/user-verify/')
>>>> verification = user_stutus.objects.get(username=user)
>>>>
>>>> *verification.status = 'Verified'#here i am changing its value and
>>>> facing the issue.*
>>>> return redirect('/user/user-login/')
>>>>
>>>> can someone give me any solution for this?
>>>> Thank you!
>>>>
>>>>
>>>>
>>>> *DISCLAIMER*
>>>>
>>>> Any views or opinions presented in this email are solely those of the
>>>> author and do not necessarily represent those of the Ganpat University.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *DISCLAIMER*
>>>>
>>>> Any views or opinions presented in this email are solely those of the
>>>> author and do not necessarily represent those of the Ganpat University.
>>>>
>>>>
>>>>
>>>> --
>>>> 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 view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>>
>> *DISCLAIMER*
>>
>> Any views or opinions presented in this email are solely those of 

Re: How to use choices in model field

2022-11-02 Thread Lloyd Leckenby
Class user_stutus?

> On Nov 2, 2022, at 9:22 AM, Aaryan R Soni  wrote:
> 
> Okay, but still the problem is that how do I set the value of status field, 
> as I have written in the code, verification.status = 'Verified' it is not 
> giving any error but it is not working either
> 
> On Wed, Nov 2, 2022, 9:51 PM kateregga julius  <mailto:julikats2...@gmail.com>> wrote:
> Don't use square blackest [ ]
> 
> status_choices=(('Unverified','Unverified'),('Verified','Verified'))
> 
> On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni  <mailto:aaryanrson...@gnu.ac.in>> wrote:
> Hey guys, i am facing some issues using choices in models.CharField. I am 
> creating a model which has username and status, where status is my choice 
> field. it has 2 values, 'Unverified' and 'Verified'.
> 
> class user_stutus(models.Model):
> status_choices=[('Unverified','Unverified'),('Verified','Verified')]
> uname=models.OneToOneField(User,on_delete=models.CASCADE)
> 
> status=models.CharField(max_length=11,choices=status_choices,default='Unverified')
> 
> def verifyCode(request):
> global errors,session
> if request.method == 'POST':
> code = request.POST['code']
> user=User.objects.get(email=session['email'])
> print('user',user)
> print('request',session['email'])
> if session['code'] != code:
> errors['code'] = 'Verification code did not match!'
> return redirect('/user/user-verify/')
> verification = user_stutus.objects.get(username=user)
> verification.status = 'Verified'#here i am changing its value and 
> facing the issue.
> return redirect('/user/user-login/')
> 
> can someone give me any solution for this?
> Thank you!
> 
>  
> DISCLAIMER
> Any views or opinions presented in this email are solely those of the author 
> and do not necessarily represent those of the Ganpat University.
>  
> 
>  
> DISCLAIMER
> Any views or opinions presented in this email are solely those of the author 
> and do not necessarily represent those of the Ganpat University.
>  
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> 
>  
> DISCLAIMER
> Any views or opinions presented in this email are solely those of the author 
> and do not necessarily represent those of the Ganpat University.
>  
> 
>  
> DISCLAIMER
> Any views or opinions presented in this email are solely those of the author 
> and do not necessarily represent those of the Ganpat University.
>  
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/907FFBEA-8FBE-4B2D-947A-39D8FE828777%40gmail.com.


Re: How to use choices in model field

2022-11-02 Thread kateregga julius
Apply a CRUD for updating the status
Wait I will send you the updated code in 30 minutes

On Wed, Nov 2, 2022, 7:23 PM Aaryan R Soni  wrote:

> Okay, but still the problem is that how do I set the value of status
> field, as I have written in the code, verification.status = 'Verified' it
> is not giving any error but it is not working either
>
> On Wed, Nov 2, 2022, 9:51 PM kateregga julius 
> wrote:
>
>> Don't use square blackest [ ]
>>
>> status_choices=(('Unverified','Unverified'),('Verified','Verified'))
>>
>> On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni 
>> wrote:
>>
>>> Hey guys, i am facing some issues using choices in models.CharField. I
>>> am creating a model which has username and status, where status is my
>>> choice field. it has 2 values, 'Unverified' and 'Verified'.
>>>
>>> class user_stutus(models.Model):
>>> status_choices=[('Unverified','Unverified'),('Verified','Verified')]
>>> uname=models.OneToOneField(User,on_delete=models.CASCADE)
>>> status=models.CharField(max_length=11,choices=status_choices,default
>>> ='Unverified')
>>>
>>> def verifyCode(request):
>>> global errors,session
>>> if request.method == 'POST':
>>> code = request.POST['code']
>>> user=User.objects.get(email=session['email'])
>>> print('user',user)
>>> print('request',session['email'])
>>> if session['code'] != code:
>>> errors['code'] = 'Verification code did not match!'
>>> return redirect('/user/user-verify/')
>>> verification = user_stutus.objects.get(username=user)
>>>
>>> *verification.status = 'Verified'#here i am changing its value and
>>> facing the issue.*
>>> return redirect('/user/user-login/')
>>>
>>> can someone give me any solution for this?
>>> Thank you!
>>>
>>>
>>>
>>> *DISCLAIMER*
>>>
>>> Any views or opinions presented in this email are solely those of the
>>> author and do not necessarily represent those of the Ganpat University.
>>>
>>>
>>>
>>>
>>>
>>> *DISCLAIMER*
>>>
>>> Any views or opinions presented in this email are solely those of the
>>> author and do not necessarily represent those of the Ganpat University.
>>>
>>>
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
>
> *DISCLAIMER*
>
> Any views or opinions presented in this email are solely those of the
> author and do not necessarily represent those of the Ganpat University.
>
>
>
>
>
> *DISCLAIMER*
>
> Any views or opinions presented in this email are solely those of the
> author and do not necessarily represent those of the Ganpat University.
>
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMVv_-EaSDUpAMW818%3Dqrdsr0yWcyXeLdbnFzEzyvd59%3DMBcSA%40mail.gmail.com.


Re: How to use choices in model field

2022-11-02 Thread Julio Cojom
When you change the status to Verified, you are only changing the object
instance in memory, to save it to the database, you need to call the method
save.

verification.save() at the end should make it work

El El mié, 2 de nov. de 2022 a la(s) 10:23, Aaryan R Soni <
aaryanrson...@gnu.ac.in> escribió:

> Okay, but still the problem is that how do I set the value of status
> field, as I have written in the code, verification.status = 'Verified' it
> is not giving any error but it is not working either
>
> On Wed, Nov 2, 2022, 9:51 PM kateregga julius 
> wrote:
>
>> Don't use square blackest [ ]
>>
>> status_choices=(('Unverified','Unverified'),('Verified','Verified'))
>>
>> On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni 
>> wrote:
>>
>>> Hey guys, i am facing some issues using choices in models.CharField. I
>>> am creating a model which has username and status, where status is my
>>> choice field. it has 2 values, 'Unverified' and 'Verified'.
>>>
>>> class user_stutus(models.Model):
>>> status_choices=[('Unverified','Unverified'),('Verified','Verified')]
>>> uname=models.OneToOneField(User,on_delete=models.CASCADE)
>>> status=models.CharField(max_length=11,choices=status_choices,default
>>> ='Unverified')
>>>
>>> def verifyCode(request):
>>> global errors,session
>>> if request.method == 'POST':
>>> code = request.POST['code']
>>> user=User.objects.get(email=session['email'])
>>> print('user',user)
>>> print('request',session['email'])
>>> if session['code'] != code:
>>> errors['code'] = 'Verification code did not match!'
>>> return redirect('/user/user-verify/')
>>> verification = user_stutus.objects.get(username=user)
>>>
>>> *verification.status = 'Verified'#here i am changing its value and
>>> facing the issue.*
>>> return redirect('/user/user-login/')
>>>
>>> can someone give me any solution for this?
>>> Thank you!
>>>
>>>
>>>
>>> *DISCLAIMER*
>>>
>>> Any views or opinions presented in this email are solely those of the
>>> author and do not necessarily represent those of the Ganpat University.
>>>
>>>
>>>
>>>
>>>
>>> *DISCLAIMER*
>>>
>>> Any views or opinions presented in this email are solely those of the
>>> author and do not necessarily represent those of the Ganpat University.
>>>
>>>
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
>
> *DISCLAIMER*
>
> Any views or opinions presented in this email are solely those of the
> author and do not necessarily represent those of the Ganpat University.
>
>
>
>
>
> *DISCLAIMER*
>
> Any views or opinions presented in this email are solely those of the
> author and do not necessarily represent those of the Ganpat University.
>
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHRQUH%3Dsb9jK0WgPf2FOUR9KebUUrsrcagG7%3DkhqPMJ_Kk0x4w%40mail.gmail.com.


Re: How to use choices in model field

2022-11-02 Thread Aaryan R Soni
Okay, but still the problem is that how do I set the value of status field,
as I have written in the code, verification.status = 'Verified' it is not
giving any error but it is not working either

On Wed, Nov 2, 2022, 9:51 PM kateregga julius 
wrote:

> Don't use square blackest [ ]
>
> status_choices=(('Unverified','Unverified'),('Verified','Verified'))
>
> On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni 
> wrote:
>
>> Hey guys, i am facing some issues using choices in models.CharField. I am
>> creating a model which has username and status, where status is my choice
>> field. it has 2 values, 'Unverified' and 'Verified'.
>>
>> class user_stutus(models.Model):
>> status_choices=[('Unverified','Unverified'),('Verified','Verified')]
>> uname=models.OneToOneField(User,on_delete=models.CASCADE)
>> status=models.CharField(max_length=11,choices=status_choices,default=
>> 'Unverified')
>>
>> def verifyCode(request):
>> global errors,session
>> if request.method == 'POST':
>> code = request.POST['code']
>> user=User.objects.get(email=session['email'])
>> print('user',user)
>> print('request',session['email'])
>> if session['code'] != code:
>> errors['code'] = 'Verification code did not match!'
>> return redirect('/user/user-verify/')
>> verification = user_stutus.objects.get(username=user)
>>
>> *verification.status = 'Verified'#here i am changing its value and
>> facing the issue.*
>> return redirect('/user/user-login/')
>>
>> can someone give me any solution for this?
>> Thank you!
>>
>>
>>
>> *DISCLAIMER*
>>
>> Any views or opinions presented in this email are solely those of the
>> author and do not necessarily represent those of the Ganpat University.
>>
>>
>>
>>
>>
>> *DISCLAIMER*
>>
>> Any views or opinions presented in this email are solely those of the
>> author and do not necessarily represent those of the Ganpat University.
>>
>>
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 


 

*DISCLAIMER*

Any
 views or opinions presented in this email are 
solely those of the 
author and do not necessarily represent those of the 
Ganpat University.

 

-- 


 

*DISCLAIMER*

Any
 views or opinions presented in this email are 
solely those of the 
author and do not necessarily represent those of the 
Ganpat University.

 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK5JjLSs9yNckAOEw0ygcXMFTkZRTZmZwAp_tPVA2n81kPzY6Q%40mail.gmail.com.


Re: How to use choices in model field

2022-11-02 Thread kateregga julius
Don't use square blackest [ ]

status_choices=(('Unverified','Unverified'),('Verified','Verified'))

On Wed, Nov 2, 2022, 5:52 PM Aaryan R Soni  wrote:

> Hey guys, i am facing some issues using choices in models.CharField. I am
> creating a model which has username and status, where status is my choice
> field. it has 2 values, 'Unverified' and 'Verified'.
>
> class user_stutus(models.Model):
> status_choices=[('Unverified','Unverified'),('Verified','Verified')]
> uname=models.OneToOneField(User,on_delete=models.CASCADE)
> status=models.CharField(max_length=11,choices=status_choices,default=
> 'Unverified')
>
> def verifyCode(request):
> global errors,session
> if request.method == 'POST':
> code = request.POST['code']
> user=User.objects.get(email=session['email'])
> print('user',user)
> print('request',session['email'])
> if session['code'] != code:
> errors['code'] = 'Verification code did not match!'
> return redirect('/user/user-verify/')
> verification = user_stutus.objects.get(username=user)
>
> *verification.status = 'Verified'#here i am changing its value and
> facing the issue.*
> return redirect('/user/user-login/')
>
> can someone give me any solution for this?
> Thank you!
>
>
>
> *DISCLAIMER*
>
> Any views or opinions presented in this email are solely those of the
> author and do not necessarily represent those of the Ganpat University.
>
>
>
>
>
> *DISCLAIMER*
>
> Any views or opinions presented in this email are solely those of the
> author and do not necessarily represent those of the Ganpat University.
>
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMVv_-E9uO8A7tJH04mHpkS-LeCwdJVKnMXtppZKkqp6JM2K5Q%40mail.gmail.com.


How to use choices in model field

2022-11-02 Thread Aaryan R Soni
Hey guys, i am facing some issues using choices in models.CharField. I am 
creating a model which has username and status, where status is my choice 
field. it has 2 values, 'Unverified' and 'Verified'.

class user_stutus(models.Model):
status_choices=[('Unverified','Unverified'),('Verified','Verified')]
uname=models.OneToOneField(User,on_delete=models.CASCADE)
status=models.CharField(max_length=11,choices=status_choices,default=
'Unverified')

def verifyCode(request):
global errors,session
if request.method == 'POST':
code = request.POST['code']
user=User.objects.get(email=session['email'])
print('user',user)
print('request',session['email'])
if session['code'] != code:
errors['code'] = 'Verification code did not match!'
return redirect('/user/user-verify/')
verification = user_stutus.objects.get(username=user)

*verification.status = 'Verified'#here i am changing its value and 
facing the issue.*
return redirect('/user/user-login/')

can someone give me any solution for this?
Thank you!

-- 


 

*DISCLAIMER*

Any
 views or opinions presented in this email are 
solely those of the 
author and do not necessarily represent those of the 
Ganpat University.

 

-- 


 

*DISCLAIMER*

Any
 views or opinions presented in this email are 
solely those of the 
author and do not necessarily represent those of the 
Ganpat University.

 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ee9dae8-2879-4c3d-a921-238b36fcb975n%40googlegroups.com.


Choices as nav link

2022-02-10 Thread gregory adomako
I have a book model with choices
I want to display the choices in the nav bar where upon clicked, will 
display all the books in with that choice

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aa26fb85-1d12-491a-a30c-cbd351d8b572n%40googlegroups.com.


Multiple Choices as Label

2022-02-02 Thread sebasti...@gmail.com
Hello,

I want in Listview on left side a filterform, where i can filter after 
sizes and/or colors. This are Multiple Choices Fields. I have attached a 
image where this fields are shown. For example XS has Key 1 and XL Key 2 
and Color Black have Key 1 then i want when user clicks on size XS,XL and 
Color Black that Post submit size=[1,2] and color=[1]

How is this possible?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4210761f-f5e1-4d72-b683-d3f5d5108f48n%40googlegroups.com.


Feedback about #27471 (Make admin's list_filter choices collapsable)

2022-01-18 Thread Marcelo Galigniana
Hello everyone!

I just pushed a patch about making the django admin filters collapsables 
when they have more than 10 options inside

I would like to read your opinions!

Here there is the PR: https://github.com/django/django/pull/15331

Thank you!

Marce.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b37bc308-a18a-41ae-b0bd-7db2d5a1b15en%40googlegroups.com.


choices = django background color

2021-11-20 Thread Jonathas Matos
Mudar condicionalmente a cor de fundo da célula no django admin 
<https://stackoverflow.com/questions/40290898/conditionally-change-background-color-of-cell-in-django-admin-list-display>

Olá Preciso retornar uma lista de opcões do mysql, cada uma com uma cor. 


models.py

STATUS_CHOICES = (
('Pendente', 
format_html('Pendente')),
('AGuardando', 
format_html('Aguardando')),
('Resolvido', 
format_html('Resolvido')),
)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, 
blank=False, null=False)


Alguém pode me ajudar?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ec931086-d720-49db-89ea-7de06f3622e0n%40googlegroups.com.


Re: django-admin doesn't display choices and it's not possible to select one

2021-09-22 Thread bnmng
Fantastic!  But now I wonder why it's not working on some of your browsers

On Wednesday, September 22, 2021 at 4:18:14 AM UTC-4 nine...@gmail.com 
wrote:

> Hi,
>
> Eureka!!! 
> Benjamin, you are right. I changed my browser and it worked.
>
> Thank for you advice.
>
> Best wishes,
> Maria
>
> On Tuesday, September 21, 2021 at 9:41:18 AM UTC+2 Mariangeles Mendoza 
> wrote:
>
>> Thank you very much!!!
>>
>> I will try other browsers. I have used Firefox and Brave.
>> No, I am not using other custom widget.
>>
>> Thanks again,
>> Maria 
>>
>> On Monday, September 20, 2021 at 1:59:25 PM UTC+2 bnmng wrote:
>>
>>> Hi.  I don't see anything in your code samples that would cause this.  
>>>  One line in admin.py caused the server to stop because of the extra 
>>> parenthesis, and the default for status should be 'r' instead of  
>>> 'refereed', but those don't cause the problem you're describing.  Maybe a 
>>> browser issue?  Maybe there's something with a custom widget that isn't the 
>>> samples?
>>>
>>> On Monday, September 13, 2021 at 9:13:48 AM UTC-4 nine...@gmail.com 
>>> wrote:
>>>
>>>> Hi,
>>>> I'm very new in Django. I'm making a cv, but I don't get select a 
>>>> choice through the django-admin web. I've searched solutions in the 
>>>> community but I cant't solve it.
>>>>
>>>> My code is:
>>>>
>>>> *Models.py*
>>>> """"
>>>> class Article(models.Model):
>>>> 
>>>> year = models.PositiveIntegerField(
>>>> validators=[
>>>> MinValueValidator(1900), 
>>>> MaxValueValidator(datetime.now().year)], null=True, 
>>>> blank=True)
>>>>
>>>> title = models.CharField(max_length=200)
>>>> author = models.ManyToManyField(Author)
>>>> journal = models.ForeignKey(Journal, models.CASCADE)
>>>> summary = models.TextField(max_length=1000, null=True, blank=True, 
>>>>help_text="Brief description of the 
>>>> article")
>>>>
>>>> PUB_TYPE = (
>>>> ('r', 'refereed'),
>>>> ('t', 'technical report'),
>>>> ('p', 'proceeding'),
>>>> ('b', 'book'),
>>>> ('c', 'book chapter'),
>>>> )
>>>>
>>>> status = models.CharField(max_length=1, choices=PUB_TYPE, 
>>>> default='refereed', 
>>>>help_text='publication type')
>>>> 
>>>> class Meta:
>>>> ordering = ['year']
>>>> 
>>>> def get_absolute_url(self):
>>>> return reverse('article-detail', args=[str(self.id)])
>>>>
>>>> def __str__(self):
>>>> return self.title
>>>> """"
>>>>
>>>> *admin.py*
>>>> """
>>>> @admin.register(Article)
>>>> class ArticleAdmin(admin.ModelAdmin):
>>>> list_display = ('title', 'journal', 'year', 'status')
>>>> list_filter = (("year", "journal")
>>>> ordering = ('-year',)
>>>> search_fields= ('author',)
>>>> filter_horizontal = ('author',)
>>>> raw_id_fields = ('journal',)
>>>> """
>>>> When I click in the status button (attached image), the  choices aren't 
>>>> displayed and i can't seletc one.
>>>> I would be very grateful for any idea.
>>>>
>>>> Thanks in advance,
>>>> Maria
>>>>
>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ae3983dd-1912-42f0-b68d-f996a495e67en%40googlegroups.com.


Re: django-admin doesn't display choices and it's not possible to select one

2021-09-22 Thread Mariangeles Mendoza
Hi,

Eureka!!! 
Benjamin, you are right. I changed my browser and it worked.

Thank for you advice.

Best wishes,
Maria

On Tuesday, September 21, 2021 at 9:41:18 AM UTC+2 Mariangeles Mendoza 
wrote:

> Thank you very much!!!
>
> I will try other browsers. I have used Firefox and Brave.
> No, I am not using other custom widget.
>
> Thanks again,
> Maria 
>
> On Monday, September 20, 2021 at 1:59:25 PM UTC+2 bnmng wrote:
>
>> Hi.  I don't see anything in your code samples that would cause this.  
>>  One line in admin.py caused the server to stop because of the extra 
>> parenthesis, and the default for status should be 'r' instead of  
>> 'refereed', but those don't cause the problem you're describing.  Maybe a 
>> browser issue?  Maybe there's something with a custom widget that isn't the 
>> samples?
>>
>> On Monday, September 13, 2021 at 9:13:48 AM UTC-4 nine...@gmail.com 
>> wrote:
>>
>>> Hi,
>>> I'm very new in Django. I'm making a cv, but I don't get select a choice 
>>> through the django-admin web. I've searched solutions in the community but 
>>> I cant't solve it.
>>>
>>> My code is:
>>>
>>> *Models.py*
>>> """"
>>> class Article(models.Model):
>>> 
>>> year = models.PositiveIntegerField(
>>> validators=[
>>> MinValueValidator(1900), 
>>> MaxValueValidator(datetime.now().year)], null=True, 
>>> blank=True)
>>>
>>> title = models.CharField(max_length=200)
>>> author = models.ManyToManyField(Author)
>>> journal = models.ForeignKey(Journal, models.CASCADE)
>>> summary = models.TextField(max_length=1000, null=True, blank=True, 
>>>help_text="Brief description of the 
>>> article")
>>>
>>> PUB_TYPE = (
>>> ('r', 'refereed'),
>>> ('t', 'technical report'),
>>> ('p', 'proceeding'),
>>> ('b', 'book'),
>>> ('c', 'book chapter'),
>>> )
>>>
>>> status = models.CharField(max_length=1, choices=PUB_TYPE, 
>>> default='refereed', 
>>>help_text='publication type')
>>> 
>>> class Meta:
>>> ordering = ['year']
>>> 
>>> def get_absolute_url(self):
>>> return reverse('article-detail', args=[str(self.id)])
>>>
>>> def __str__(self):
>>> return self.title
>>> """"
>>>
>>> *admin.py*
>>> """
>>> @admin.register(Article)
>>> class ArticleAdmin(admin.ModelAdmin):
>>> list_display = ('title', 'journal', 'year', 'status')
>>> list_filter = (("year", "journal")
>>> ordering = ('-year',)
>>> search_fields= ('author',)
>>> filter_horizontal = ('author',)
>>> raw_id_fields = ('journal',)
>>> """
>>> When I click in the status button (attached image), the  choices aren't 
>>> displayed and i can't seletc one.
>>> I would be very grateful for any idea.
>>>
>>> Thanks in advance,
>>> Maria
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61e348de-660e-4cdd-bf39-ef14d839198bn%40googlegroups.com.


Re: django-admin doesn't display choices and it's not possible to select one

2021-09-21 Thread Mariangeles Mendoza
Thank you very much!!!

I will try other browsers. I have used Firefox and Brave.
No, I am not using other custom widget.

Thanks again,
Maria 

On Monday, September 20, 2021 at 1:59:25 PM UTC+2 bnmng wrote:

> Hi.  I don't see anything in your code samples that would cause this.  
>  One line in admin.py caused the server to stop because of the extra 
> parenthesis, and the default for status should be 'r' instead of  
> 'refereed', but those don't cause the problem you're describing.  Maybe a 
> browser issue?  Maybe there's something with a custom widget that isn't the 
> samples?
>
> On Monday, September 13, 2021 at 9:13:48 AM UTC-4 nine...@gmail.com wrote:
>
>> Hi,
>> I'm very new in Django. I'm making a cv, but I don't get select a choice 
>> through the django-admin web. I've searched solutions in the community but 
>> I cant't solve it.
>>
>> My code is:
>>
>> *Models.py*
>> """"
>> class Article(models.Model):
>> 
>> year = models.PositiveIntegerField(
>> validators=[
>> MinValueValidator(1900), 
>> MaxValueValidator(datetime.now().year)], null=True, 
>> blank=True)
>>
>> title = models.CharField(max_length=200)
>> author = models.ManyToManyField(Author)
>> journal = models.ForeignKey(Journal, models.CASCADE)
>> summary = models.TextField(max_length=1000, null=True, blank=True, 
>>help_text="Brief description of the 
>> article")
>>
>> PUB_TYPE = (
>> ('r', 'refereed'),
>> ('t', 'technical report'),
>> ('p', 'proceeding'),
>> ('b', 'book'),
>> ('c', 'book chapter'),
>> )
>>
>> status = models.CharField(max_length=1, choices=PUB_TYPE, 
>> default='refereed', 
>>help_text='publication type')
>> 
>> class Meta:
>> ordering = ['year']
>> 
>> def get_absolute_url(self):
>> return reverse('article-detail', args=[str(self.id)])
>>
>> def __str__(self):
>> return self.title
>> """"
>>
>> *admin.py*
>> """
>> @admin.register(Article)
>> class ArticleAdmin(admin.ModelAdmin):
>> list_display = ('title', 'journal', 'year', 'status')
>> list_filter = (("year", "journal")
>> ordering = ('-year',)
>> search_fields= ('author',)
>> filter_horizontal = ('author',)
>> raw_id_fields = ('journal',)
>> """
>> When I click in the status button (attached image), the  choices aren't 
>> displayed and i can't seletc one.
>> I would be very grateful for any idea.
>>
>> Thanks in advance,
>> Maria
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/08bb4225-200e-4c1f-bfca-09c2b05fa9c5n%40googlegroups.com.


Re: django-admin doesn't display choices and it's not possible to select one

2021-09-20 Thread bnmng
Hi.  I don't see anything in your code samples that would cause this.   One 
line in admin.py caused the server to stop because of the extra 
parenthesis, and the default for status should be 'r' instead of  
'refereed', but those don't cause the problem you're describing.  Maybe a 
browser issue?  Maybe there's something with a custom widget that isn't the 
samples?

On Monday, September 13, 2021 at 9:13:48 AM UTC-4 nine...@gmail.com wrote:

> Hi,
> I'm very new in Django. I'm making a cv, but I don't get select a choice 
> through the django-admin web. I've searched solutions in the community but 
> I cant't solve it.
>
> My code is:
>
> *Models.py*
> """"
> class Article(models.Model):
> 
> year = models.PositiveIntegerField(
> validators=[
> MinValueValidator(1900), 
> MaxValueValidator(datetime.now().year)], null=True, 
> blank=True)
>
> title = models.CharField(max_length=200)
> author = models.ManyToManyField(Author)
> journal = models.ForeignKey(Journal, models.CASCADE)
> summary = models.TextField(max_length=1000, null=True, blank=True, 
>help_text="Brief description of the 
> article")
>
> PUB_TYPE = (
> ('r', 'refereed'),
> ('t', 'technical report'),
> ('p', 'proceeding'),
> ('b', 'book'),
> ('c', 'book chapter'),
> )
>
> status = models.CharField(max_length=1, choices=PUB_TYPE, 
> default='refereed', 
>help_text='publication type')
> 
> class Meta:
> ordering = ['year']
> 
> def get_absolute_url(self):
> return reverse('article-detail', args=[str(self.id)])
>
> def __str__(self):
> return self.title
> """"
>
> *admin.py*
> """
> @admin.register(Article)
> class ArticleAdmin(admin.ModelAdmin):
> list_display = ('title', 'journal', 'year', 'status')
> list_filter = (("year", "journal")
> ordering = ('-year',)
> search_fields= ('author',)
> filter_horizontal = ('author',)
> raw_id_fields = ('journal',)
> """
> When I click in the status button (attached image), the  choices aren't 
> displayed and i can't seletc one.
> I would be very grateful for any idea.
>
> Thanks in advance,
> Maria
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3cc17c27-7c78-4f60-8a59-894711f182a1n%40googlegroups.com.


django-admin doesn't display choices and it's not possible to select one

2021-09-13 Thread Mariangeles Mendoza
Hi,
I'm very new in Django. I'm making a cv, but I don't get select a choice 
through the django-admin web. I've searched solutions in the community but 
I cant't solve it.

My code is:

*Models.py*
""""
class Article(models.Model):

year = models.PositiveIntegerField(
validators=[
MinValueValidator(1900), 
MaxValueValidator(datetime.now().year)], null=True, 
blank=True)
   
title = models.CharField(max_length=200)
author = models.ManyToManyField(Author)
journal = models.ForeignKey(Journal, models.CASCADE)
summary = models.TextField(max_length=1000, null=True, blank=True, 
   help_text="Brief description of the article")
   
PUB_TYPE = (
('r', 'refereed'),
('t', 'technical report'),
('p', 'proceeding'),
('b', 'book'),
('c', 'book chapter'),
)

status = models.CharField(max_length=1, choices=PUB_TYPE, 
default='refereed', 
   help_text='publication type')

class Meta:
ordering = ['year']

def get_absolute_url(self):
return reverse('article-detail', args=[str(self.id)])

def __str__(self):
return self.title
""""

*admin.py*
"""
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'journal', 'year', 'status')
list_filter = (("year", "journal")
ordering = ('-year',)
search_fields= ('author',)
filter_horizontal = ('author',)
raw_id_fields = ('journal',)
"""
When I click in the status button (attached image), the  choices aren't 
displayed and i can't seletc one.
I would be very grateful for any idea.

Thanks in advance,
Maria

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30490e97-5c14-436b-970e-17676ad0d420n%40googlegroups.com.


Re: CHOICES

2021-06-13 Thread Nikeet NA
from django.db.models import Sum, DecimalField
from django.db.models.functions import Cast

Model.objects.annotate(deci_con_factor=Cast('conversion_factor', 
DecimalField()).aggregate(sum=Sum('deci_con_factor')).get('sum')

You need to change your char type to decimal type , you can use CAST 
operator, you will cast you charfield to decimal field and annotate it on 
every object then use that annotated field in aggregate func. 

On Sunday, 13 June 2021 at 15:38:05 UTC+5:30 sebasti...@gmail.com wrote:

> Hello,
>
> i think this is the right answer:
>
> from django.db.models import Sum
>
> ModelName.objects.filter(field_name__isnull=True).aggregate(Sum('field_name'))#
>  returns {'field_name__sum': 1000} for example
>
>
> Am So., 13. Juni 2021 um 12:04 Uhr schrieb www.forum-gh.com <
> lada...@gmail.com>:
>
>> Hello friends 
>> please i have: conversion_fqctor = models.charfield(choices=FACTOR)
>>
>> i want to sum the conversion_factor inside my view.py how do i convert it 
>> to a decimal and use the Sum()
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1eff5efd-0d61-4d5d-8dca-1cbdd7aa4a85n%40googlegroups.com.


Re: CHOICES

2021-06-13 Thread Sebastian Jung
Hello,

i think this is the right answer:

from django.db.models import Sum

ModelName.objects.filter(field_name__isnull=True).aggregate(Sum('field_name'))#
returns {'field_name__sum': 1000} for example


Am So., 13. Juni 2021 um 12:04 Uhr schrieb www.forum-gh.com <
ladamo...@gmail.com>:

> Hello friends
> please i have: conversion_fqctor = models.charfield(choices=FACTOR)
>
> i want to sum the conversion_factor inside my view.py how do i convert it
> to a decimal and use the Sum()
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mzh5hoTgESsxFiUtkT_S-cPvTSjNGp-zUAfSwSptAaZJw%40mail.gmail.com.


CHOICES

2021-06-13 Thread www.forum-gh.com
Hello friends
please i have: conversion_fqctor = models.charfield(choices=FACTOR)

i want to sum the conversion_factor inside my view.py how do i convert it
to a decimal and use the Sum()

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com.


Re: Limit the choices for a ForeignKey

2020-10-11 Thread Dvs Khamele
Hi do you hire contract based python/django freelancer?
We can help you in this and related techincal tasks at fair prices. Reply
or send email to divy...@pythonmate.com
Best Regards,
Divyesh Khamele,
Pythonmate


On Sun, 27 Sep 2020, 10:09 pm Marco Paradisi,  wrote:

> Hi Everyone!
>
> I need to filter the choices for a foreign key.
>
> My Model has an attribute SEX that could be M or F, and two Foreign keys (
> FATHER and MOTHER ), I want both filtered for sex.
>
> How can I achieve it?
>
> Thanks in advance
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFCTdWp0xJE_J-r%3DmHbHzVmeAsGvotFc1%3DyQBGuyEzjfiiVxTA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFCTdWp0xJE_J-r%3DmHbHzVmeAsGvotFc1%3DyQBGuyEzjfiiVxTA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH9mneV4zRCirCcXOV5bV7fCyb7HmB7kHDK8Lumu2hKqMN10YA%40mail.gmail.com.


Re: Limit the choices for a ForeignKey

2020-09-27 Thread RANGA BHARATH JINKA
Hi,

Check this. This may be useful for you. It is based on dependent
dropdown.

https://www.youtube.com/watch?v=U_qPp6vPl-g

On Sun, Sep 27, 2020 at 10:09 PM Marco Paradisi  wrote:

> Hi Everyone!
>
> I need to filter the choices for a foreign key.
>
> My Model has an attribute SEX that could be M or F, and two Foreign keys (
> FATHER and MOTHER ), I want both filtered for sex.
>
> How can I achieve it?
>
> Thanks in advance
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFCTdWp0xJE_J-r%3DmHbHzVmeAsGvotFc1%3DyQBGuyEzjfiiVxTA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFCTdWp0xJE_J-r%3DmHbHzVmeAsGvotFc1%3DyQBGuyEzjfiiVxTA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK5m314V6rMaarKnx3rV4uNO%3DfKo-24JsNLczFddDNShN65mmw%40mail.gmail.com.


Limit the choices for a ForeignKey

2020-09-27 Thread Marco Paradisi
Hi Everyone!

I need to filter the choices for a foreign key.

My Model has an attribute SEX that could be M or F, and two Foreign keys (
FATHER and MOTHER ), I want both filtered for sex.

How can I achieve it?

Thanks in advance

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFCTdWp0xJE_J-r%3DmHbHzVmeAsGvotFc1%3DyQBGuyEzjfiiVxTA%40mail.gmail.com.


Re: forms.ChoiceField calls choices callback twice?

2020-08-27 Thread Roy Smith
Hmmm, maybe related to https://code.djangoproject.com/ticket/26665 ?

On Thursday, August 27, 2020 at 5:29:39 PM UTC-4 Roy Smith wrote:

> I'm running:
>
> Python 3.7
> Django 2.2
> Debian 4.9
>
> If I configure a forms ChoiceField with a callback function for choices, 
> it gets called twice each time I render the form:
>
> from unittest import TestCase
> from django import forms
>
> def callback():
> print("callback")
> return [('foo', 'bar')]
>
> class MyForm(forms.Form):
> f = forms.ChoiceField(choices=callback)
>
>
> class FormTest(TestCase):
> MyForm().as_p()
>
>
>
> prints:
>
> ./manage.py test spi.test_f
> callback
> callback
> System check identified no issues (0 silenced).
>
> --
> Ran 0 tests in 0.000s
>
> OK
>
>
> Is this a known issue?
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24a524a6-5c47-42f7-ba63-37c77b09da34n%40googlegroups.com.


forms.ChoiceField calls choices callback twice?

2020-08-27 Thread Roy Smith
I'm running:

Python 3.7
Django 2.2
Debian 4.9

If I configure a forms ChoiceField with a callback function for choices, it 
gets called twice each time I render the form:

> from unittest import TestCase
> from django import forms
> 
> def callback():
> print("callback")
> return [('foo', 'bar')]
> 
> class MyForm(forms.Form):
> f = forms.ChoiceField(choices=callback)
> 
> 
> class FormTest(TestCase):
> MyForm().as_p()


prints:

> ./manage.py test spi.test_f
> callback
> callback
> System check identified no issues (0 silenced).
> 
> --
> Ran 0 tests in 0.000s
> 
> OK

Is this a known issue?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D7AA7EED-1D58-4A8C-A931-A6653D390135%40panix.com.


how to override options of choices in django model form

2020-07-28 Thread Sujata Aghor
Hello All,

How can I override options of choices in django model form from the model
field ?
Below is my code -

*models.py:*

class XXX(models.Model):
StatusType = models.TextChoices('StatusType', const.status_values)
status = models.CharField(max_length=100, default='abc',
choices=StatusType.choices,)


*views.py:*

class XXXUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = XXX
fields = ['aaa', 'bbb', 'status']

def get_form(self):
form = super().get_form()
form.title = self.kwargs['title']
   # NOW HERE I WANT TO RESET THE VALUE OF STATUS DROPDOWN BASED ON
CERTAIN CONDITION.
return form
-- 

Can anyone suggest something
Thanks in advance !

Thanks & Regards!
Sujata S. Aghor

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJCP8KB06LxS8m8iNfpe0h30Sa%3Dro2N1AuyGM4sQXreW4f-Pig%40mail.gmail.com.


Re: Populate choices from existing values in a model field

2020-06-23 Thread Patrick Carra
I'm not directly modifying any code in a .py file I am simply adding a 
value to the database table but I am unable to see the change reflected in 
my drop down lists until I restart the server.  Is there a better way of 
populating choices for my drop down menu?  Or could I simply add a cron job 
that restarts the server periodically(this seems like not a great solution).

On Saturday, June 20, 2020 at 8:39:03 AM UTC-5, Integr@te System wrote:
>
> Hi Patrick,
>
> Plz review for your suitable case:
> https://stackoverflow.com/questions/3742734/django-restart-server-or-httpd
>
> Nice.
>
> On Sat, Jun 20, 2020, 1:32 AM Patrick Carra  > wrote:
>
>> I am trying to read distinct values from a model field and use the tuple 
>> list to populate the choices in a Form.  The problem I have is that every 
>> time a new value is added I must reset the httpd server in order to include 
>> the new value in the form.  I have researched and tried this a few 
>> different ways but so far am unable to come up with a better solution. Any 
>> ideas?
>>
>> *models.py*
>> class Circuitinfotable(models.Model):
>> id1 = models.IntegerField(primary_key=True, blank=True,null=False,
>> unique=True)
>> pathname = models.CharField(max_length=255, blank=True, null=True)
>> segmentname = models.CharField(max_length=255, blank=True, null=True)
>> region = models.CharField(max_length=255, blank=True, null=True)
>>
>>
>>
>>
>>
>> *forms.py*
>> def getList(item_list, keyValue):
>> valueList=[]
>> for each in item_list:
>> valueList.append(each[keyValue])
>> return valueList
>>
>> def listCreator(field, query):
>> newList_query = getList(query, field)
>> sorted_newList = sorted(getUnique(newList_query))
>> sorted_newList.insert(0, ("", ""))
>> return sorted_newList
>>
>>
>> class CircuitinfotableForm(ModelForm):
>>
>>
>> class Meta:
>> pathlistQuery = Circuitinfotable.objects.all().values('pathname'
>> ).exclude(pathname=None).exclude(pathname='None')
>>     path_list = listCreator('pathname', pathlistQuery)
>>
>>
>> model = Circuitinfotable
>> fields = ['circuitid', 'pathname', 'segmentname', 'region']
>> widgets = {'circuitid': forms.TextInput(attrs={'size':40}), 
>> 'pathname': forms.Select(choices=path_list), 'segmentname': forms.Select(
>> choices=segment_list),
>>'region':  forms.Select(choices=region_list)}
>>
>> I shortened this code to only include some of the relevant fields and 
>> code for brevity.  Here I created two functions to create a list of tuples 
>> for pathname from the values I retrieve using a query and pass it to the 
>> Select widget using choices.
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/66b8fce5-43c6-48a6-a873-2527bdf2b126o%40googlegroups.com.


Re: Populate choices from existing values in a model field

2020-06-20 Thread Integr@te System
Hi Patrick,

Plz review for your suitable case:
https://stackoverflow.com/questions/3742734/django-restart-server-or-httpd

Nice.

On Sat, Jun 20, 2020, 1:32 AM Patrick Carra  wrote:

> I am trying to read distinct values from a model field and use the tuple
> list to populate the choices in a Form.  The problem I have is that every
> time a new value is added I must reset the httpd server in order to include
> the new value in the form.  I have researched and tried this a few
> different ways but so far am unable to come up with a better solution. Any
> ideas?
>
> *models.py*
> class Circuitinfotable(models.Model):
> id1 = models.IntegerField(primary_key=True, blank=True,null=False,
> unique=True)
> pathname = models.CharField(max_length=255, blank=True, null=True)
> segmentname = models.CharField(max_length=255, blank=True, null=True)
> region = models.CharField(max_length=255, blank=True, null=True)
>
>
>
>
>
> *forms.py*
> def getList(item_list, keyValue):
> valueList=[]
> for each in item_list:
> valueList.append(each[keyValue])
> return valueList
>
> def listCreator(field, query):
> newList_query = getList(query, field)
> sorted_newList = sorted(getUnique(newList_query))
> sorted_newList.insert(0, ("", ""))
> return sorted_newList
>
>
> class CircuitinfotableForm(ModelForm):
>
>
> class Meta:
> pathlistQuery = Circuitinfotable.objects.all().values('pathname').
> exclude(pathname=None).exclude(pathname='None')
> path_list = listCreator('pathname', pathlistQuery)
>
>
> model = Circuitinfotable
> fields = ['circuitid', 'pathname', 'segmentname', 'region']
> widgets = {'circuitid': forms.TextInput(attrs={'size':40}),
> 'pathname': forms.Select(choices=path_list), 'segmentname': forms.Select(
> choices=segment_list),
>'region':  forms.Select(choices=region_list)}
>
> I shortened this code to only include some of the relevant fields and code
> for brevity.  Here I created two functions to create a list of tuples for
> pathname from the values I retrieve using a query and pass it to the Select
> widget using choices.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP5HUWoZ9u6tC0%2B7Mxx%3D9Cc1mQPmSD_a%2BqJKvwdwEuhE6bCivQ%40mail.gmail.com.


Populate choices from existing values in a model field

2020-06-19 Thread Patrick Carra
I am trying to read distinct values from a model field and use the tuple 
list to populate the choices in a Form.  The problem I have is that every 
time a new value is added I must reset the httpd server in order to include 
the new value in the form.  I have researched and tried this a few 
different ways but so far am unable to come up with a better solution. Any 
ideas?

*models.py*
class Circuitinfotable(models.Model):
id1 = models.IntegerField(primary_key=True, blank=True,null=False,unique
=True)
pathname = models.CharField(max_length=255, blank=True, null=True)
segmentname = models.CharField(max_length=255, blank=True, null=True)
region = models.CharField(max_length=255, blank=True, null=True)





*forms.py*
def getList(item_list, keyValue):
valueList=[]
for each in item_list:
valueList.append(each[keyValue])
return valueList

def listCreator(field, query):
newList_query = getList(query, field)
sorted_newList = sorted(getUnique(newList_query))
sorted_newList.insert(0, ("", ""))
return sorted_newList


class CircuitinfotableForm(ModelForm):


class Meta:
pathlistQuery = Circuitinfotable.objects.all().values('pathname').
exclude(pathname=None).exclude(pathname='None')
path_list = listCreator('pathname', pathlistQuery)


model = Circuitinfotable
fields = ['circuitid', 'pathname', 'segmentname', 'region']
widgets = {'circuitid': forms.TextInput(attrs={'size':40}), 
'pathname': forms.Select(choices=path_list), 'segmentname': forms.Select(
choices=segment_list),
   'region':  forms.Select(choices=region_list)}

I shortened this code to only include some of the relevant fields and code 
for brevity.  Here I created two functions to create a list of tuples for 
pathname from the values I retrieve using a query and pass it to the Select 
widget using choices.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com.


Re: Models as choices

2020-04-17 Thread Esther Camilo
This guy has plenty of tutorials building complete applications. As
front-end you can use Bootstrap in your templates
https://simpleisbetterthancomplex.com/



On Fri, Apr 17, 2020 at 9:57 AM Denilson Antonio Avellan <
denilson.d...@gmail.com> wrote:

> me pueden enviar el codigo completo ? para hacer un login solo la
> interfqaz grafica sin nada de conexion a base de datos porfavor!
>
> El vie., 17 de abr. de 2020 a la(s) 00:00, Gavin Wiener (
> gavinwie...@gmail.com) escribió:
>
>> If you're serializing as JSON, that primary key is literally just integer
>> then, and the foreign key relationship requires an instance of that foreign
>> key. So you'll need to fetch an instance of the object first.
>>
>> I've had this issue before, that's how I resolved it.
>>
>> On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L
>> wrote:
>>>
>>> i get this error when trying in your way:
>>>
>>> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>>>
>>> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>>>
>>>> Couldn't the User just have a ForeignKey on countries?
>>>>
>>>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L
>>>> wrote:
>>>>>
>>>>> how can i use model x values as choices for model y ?
>>>>>
>>>>> for eg:
>>>>> class countries(models.Model):
>>>>>  country = models.CharField(max_length=200)
>>>>>
>>>>>  def __str__(self):
>>>>>  return self.country
>>>>>
>>>>> class User(AbstractUser):
>>>>>  """User model."""
>>>>>
>>>>>  username = None
>>>>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full
>>>>> Name")
>>>>>  country_choices = models.CharField(choices=countries
>>>>>
>>>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALVb5jEr-MnU7Z_6x%2BD30RrHGT4zBVSCsRGK4eGpikLXR%2BRQow%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALVb5jEr-MnU7Z_6x%2BD30RrHGT4zBVSCsRGK4eGpikLXR%2BRQow%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB8U4xO_ca0qcuJsvBGVRWpU1ctvQUsdSiFSUwWqO-ys4gE47Q%40mail.gmail.com.


Re: Models as choices

2020-04-17 Thread Denilson Antonio Avellan
me pueden enviar el codigo completo ? para hacer un login solo la
interfqaz grafica sin nada de conexion a base de datos porfavor!

El vie., 17 de abr. de 2020 a la(s) 00:00, Gavin Wiener (
gavinwie...@gmail.com) escribió:

> If you're serializing as JSON, that primary key is literally just integer
> then, and the foreign key relationship requires an instance of that foreign
> key. So you'll need to fetch an instance of the object first.
>
> I've had this issue before, that's how I resolved it.
>
> On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote:
>>
>> i get this error when trying in your way:
>>
>> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>>
>> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>>
>>> Couldn't the User just have a ForeignKey on countries?
>>>
>>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L
>>> wrote:
>>>>
>>>> how can i use model x values as choices for model y ?
>>>>
>>>> for eg:
>>>> class countries(models.Model):
>>>>  country = models.CharField(max_length=200)
>>>>
>>>>  def __str__(self):
>>>>  return self.country
>>>>
>>>> class User(AbstractUser):
>>>>  """User model."""
>>>>
>>>>  username = None
>>>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full
>>>> Name")
>>>>  country_choices = models.CharField(choices=countries
>>>>
>>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALVb5jEr-MnU7Z_6x%2BD30RrHGT4zBVSCsRGK4eGpikLXR%2BRQow%40mail.gmail.com.


Re: Models as choices

2020-04-16 Thread Gavin Wiener
If you're serializing as JSON, that primary key is literally just integer 
then, and the foreign key relationship requires an instance of that foreign 
key. So you'll need to fetch an instance of the object first.

I've had this issue before, that's how I resolved it.

On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote:
>
> i get this error when trying in your way:
>
> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>
> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>
>> Couldn't the User just have a ForeignKey on countries?
>>
>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
>> wrote:
>>>
>>> how can i use model x values as choices for model y ?
>>>
>>> for eg:
>>> class countries(models.Model):
>>>  country = models.CharField(max_length=200)
>>>
>>>  def __str__(self):
>>>  return self.country 
>>>
>>> class User(AbstractUser):
>>>  """User model."""
>>>
>>>  username = None
>>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
>>> Name") 
>>>  country_choices = models.CharField(choices=countries
>>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L
i get this error when trying in your way:

Cannot assign "2": "User.highest_degree" must be a "Degree" instance.

On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>
> Couldn't the User just have a ForeignKey on countries?
>
> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
> wrote:
>>
>> how can i use model x values as choices for model y ?
>>
>> for eg:
>> class countries(models.Model):
>>  country = models.CharField(max_length=200)
>>
>>  def __str__(self):
>>  return self.country 
>>
>> class User(AbstractUser):
>>  """User model."""
>>
>>  username = None
>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
>> Name") 
>>  country_choices = models.CharField(choices=countries
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7031af8-272d-4fe5-b13a-406e0162385e%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Gavin Wiener
Couldn't the User just have a ForeignKey on countries?

On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg:
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b1d051a8-ee61-4b0a-b5e4-66d0315306fa%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L
Thanks for helping me out .

On Thursday, April 16, 2020 at 2:34:13 PM UTC+5:30, Kasper Laudrup wrote:
>
> Hi Shreehari 
>
> On 16/04/2020 10.17, shreehari Vaasistha L wrote: 
> > Object of type ValueError is not JSON serializable 
> > 
> > 
> > getting this above error 
> > 
>
> First of all, don't highjack other unrelated threads. Create your own 
> with a descriptive subject. 
>
> You get the error because of the lines: 
>
> except Exception as e: 
> return Response(e) 
>
> You cannot serialize the exception object, but your real problem is most 
> likely the actual exception being thrown. 
>
> Try to remove the entire try/except block. You most likely don't want to 
> return errors in your code to the user anyway so returning an HTTP 500 
> to the user and letting Django write the exception message and 
> stacktrace in your log is probably much better. 
>
> Kind regards, 
>
> Kasper Laudrup 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87eade6b-38e0-4b61-9d3f-0d6f08b2ed85%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Kasper Laudrup

Hi Shreehari

On 16/04/2020 10.17, shreehari Vaasistha L wrote:

Object of type ValueError is not JSON serializable


getting this above error



First of all, don't highjack other unrelated threads. Create your own 
with a descriptive subject.


You get the error because of the lines:

except Exception as e:
   return Response(e)

You cannot serialize the exception object, but your real problem is most 
likely the actual exception being thrown.


Try to remove the entire try/except block. You most likely don't want to 
return errors in your code to the user anyway so returning an HTTP 500 
to the user and letting Django write the exception message and 
stacktrace in your log is probably much better.


Kind regards,

Kasper Laudrup

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6c85506-e72b-fd3f-b79a-67412641007b%40stacktrace.dk.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L


Object of type ValueError is not JSON serializable

getting this above error.

here's my views.py
class UserCreateApiView(CreateAPIView):
   serializer_class = UserCreateSerializer
   def post(self,request):
   try:
   serializer=UserCreateSerializer(data=request.data)
   if serializer.is_valid():
   new_user = User()

new_user.highest_degree=serializer.data['highest_degree']
   
#new_user.state_registered=serializer.data['state_registered']
   new_user.country_choices=serializer.data['country_choices']

new_user.save()
   print(new_user.doc_id)
   return Response(status=status.HTTP_200_OK)
   return Response(status=status.HTTP_406_NOT_ACCEPTABLE)
   except Exception as e:
   return Response(e)
have mentioned all fields in serializers.py



On Thursday, April 16, 2020 at 12:57:16 PM UTC+5:30, Antje Kazimiers wrote:
>
> with a Foreign Key field, one-to-many relationship:
>
> https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
>
> Antje
> On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg: 
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
> -- 
> 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87fad0b6-96d2-43fc-87cf-ffdddc855c5f%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L


Object of type ValueError is not JSON serializable


getting this above error

On Thursday, April 16, 2020 at 12:57:16 PM UTC+5:30, Antje Kazimiers wrote:
>
> with a Foreign Key field, one-to-many relationship:
>
> https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
>
> Antje
> On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg: 
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
> -- 
> 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12580555-d71d-435c-abbb-449a260fdfe7%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Antje Kazimiers
with a Foreign Key field, one-to-many relationship:

https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/

Antje

On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
> how can i use model x values as choices for model y ?
>
> for eg:
> |
> classcountries(models.Model):
>  country =models.CharField(max_length=200)
>
>  def__str__(self):
>  returnself.country
>
> classUser(AbstractUser):
>  """User model."""
>
>  username =None
>  full_name =models.CharField(_("Full
> Name"),max_length=50,default="Full Name")
>  country_choices =models.CharField(choices=countries
> |
> -- 
> 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
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f6aeed6e-de34-f8f6-ce26-31151d4dee83%40gmail.com.


Models as choices

2020-04-15 Thread shreehari Vaasistha L
how can i use model x values as choices for model y ?

for eg:
class countries(models.Model):
 country = models.CharField(max_length=200)

 def __str__(self):
 return self.country 

class User(AbstractUser):
 """User model."""

 username = None
 full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
Name") 
 country_choices = models.CharField(choices=countries

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com.


Re: Study on annotation of design and implementation choices, and of technical debt

2020-03-23 Thread Motaz Hejaze
Out of topic , but i wish you all the best fighting corona virus ..

On Mon, 23 Mar 2020, 9:23 pm Alexander Serebrenik, 
wrote:

> Dear all,
>
>
> As software engineering research teams at the University of Sannio (Italy)
> and Eindhoven University of Technology (The Netherlands) we are interested
> in investigating the protocol used by developers while they have to
> annotate implementation and design choices during their normal development
> activities. More specifically, we are looking at whether, where and what
> kind of annotations developers usually use trying to be focused more on
> those annotations mainly aimed at highlighting that the code is not in the
> right shape (e.g., comments for annotating delayed or intended work
> activities such as TODO, FIXME, hack, workaround, etc). In the latter case,
> we are looking at what is the content of the above annotations, as well as
> how they usually behave while evolving the code that has been previously
> annotated.
>
>
> When answering the survey, in case your annotation practices are different
> in different open source projects you may contribute, please refer to how
> you behave for the projects where you have been contacted.
>
>
> Filling out the survey will take about 5 minutes.
>
>
> Please note that your identity and personal data will not be disclosed,
> while we plan to use the aggregated results and anonymized responses as
> part of a scientific publication.
>
>
> If you have any questions about the questionnaire or our research, please
> do not hesitate to contact us.
>
>
> You can find the survey link here:
>
>
> https://forms.gle/NxdVXiZQSmQ15U4T8
>
>
> Thanks and regards,
>
>
> Gianmarco Fucci (gianmarcofucc...@gmail.com)
>
> Fiorella Zampetti (fzampe...@unisannio.it)
>
> Alexander Serebrenik (a.serebre...@tue.nl)
>
> Massimiliano Di Penta (dipe...@unisannio.it)
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4f9a83ba-4e71-444f-9c52-c2a0aa58748b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4f9a83ba-4e71-444f-9c52-c2a0aa58748b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-e11kk95sOz2Fhrh29-5KnniuSKJRP9Ot1-i03o42vynA%40mail.gmail.com.


Study on annotation of design and implementation choices, and of technical debt

2020-03-23 Thread Alexander Serebrenik


Dear all,


As software engineering research teams at the University of Sannio (Italy) 
and Eindhoven University of Technology (The Netherlands) we are interested 
in investigating the protocol used by developers while they have to 
annotate implementation and design choices during their normal development 
activities. More specifically, we are looking at whether, where and what 
kind of annotations developers usually use trying to be focused more on 
those annotations mainly aimed at highlighting that the code is not in the 
right shape (e.g., comments for annotating delayed or intended work 
activities such as TODO, FIXME, hack, workaround, etc). In the latter case, 
we are looking at what is the content of the above annotations, as well as 
how they usually behave while evolving the code that has been previously 
annotated.


When answering the survey, in case your annotation practices are different 
in different open source projects you may contribute, please refer to how 
you behave for the projects where you have been contacted.


Filling out the survey will take about 5 minutes.


Please note that your identity and personal data will not be disclosed, 
while we plan to use the aggregated results and anonymized responses as 
part of a scientific publication. 


If you have any questions about the questionnaire or our research, please 
do not hesitate to contact us.


You can find the survey link here:


https://forms.gle/NxdVXiZQSmQ15U4T8


Thanks and regards,


Gianmarco Fucci (gianmarcofucc...@gmail.com)

Fiorella Zampetti (fzampe...@unisannio.it)

Alexander Serebrenik (a.serebre...@tue.nl)

Massimiliano Di Penta (dipe...@unisannio.it)

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4f9a83ba-4e71-444f-9c52-c2a0aa58748b%40googlegroups.com.


Django formset, forms passing unique choices into a choicefield for each form

2019-12-18 Thread Brad Allgood
Initially posted on stack overflow:

https://stackoverflow.com/questions/59395761/passing-dynamic-choices-into-a-formset-unique-for-each-form

I am working on what I thought was a simple college football confidence 
pool. The concept is as follows:

   - Bowl Model: Model that stores information of each bowl game being 
   played this season
   - Team Model: Model for all the teams playing in a bowl with a foreign 
   key to the bowl

models.py

from django.db import models
from django.contrib.auth.models import Group, User

class Bowl(models.Model):
"""Model for Bowl Game information"""
name = models.CharField(max_length=200)
b_date = models.DateField(null=True, blank=True)
b_time = models.TimeField(null=True, blank=True)
tv = models.CharField(max_length=10)
location = models.CharField(max_length=200)

def __str__(self):
"""String for representing the bowl object"""
return self.name

class Team(models.Model):
name = models.CharField(max_length=200)
bowl = models.ForeignKey(Bowl,on_delete=models.SET_NULL,null=True)

def __str__(self):
"""String for representing the intermediate table"""
return self.name   

I'm attempting to create a page has a formset which allows the user to pick 
the predicted winner of each game. Therefore I constructed the following 
view to call the form and formset.
views.py

   def fs_test(request):

   bowl_list = Bowl.objects.all()
   bowl_len = len(bowl_list)
   bowl_data = []

   TestFormSet = formset_factory(TestForm, extra=0)

   for bowl in bowl_list:
  bowl_data.append({
  't_bowl': bowl.name,'t_user':request.user,'t_weight':1,
  't_winner':winner_data,
  })

   if request.method == 'POST':
   pass
   else:
   formset = TestFormSet(initial=bowl_data)

   context = {
   'formset':formset, 'bowl_data':bowl_data
   }
   return render(request, 'catalog/test_bowl.html',context)

The following form inherits pre-populated data via passing "bowl_data" in 
the "initial" parameter.
forms.py

class TestForm(forms.Form):
 def __init__(self, *args, **kwargs):
 super(TestForm, self).__init__(*args, **kwargs)
 self.fields['t_bowl'] = forms.CharField()
 self.fields['t_weight'] = forms.IntegerField()
 self.fields['t_user'] = forms.CharField()
 self.fields['t_winner'] = forms.ChoiceField(
     widget=forms.RadioSelect,
 required=True,
 choices=[(o.name, o.name)
 for o in Team.objects.filter(bowl__name__exact=self.t_bowl)]
 )

I believe pre-populating the t_winner choices are failing because using the 
self.t_bowl in the query is just a field reference not the name of the 
field. I don't know how to pass in the "bowl" name to the form query. Or 
maybe I pre-populate the "choices" in the view but I don't know how to pass 
a dict into it and reference the correct index.

I've done some reading on the get_form_kwargs, but I'm not clear on how to 
use it in this instance.

It's entirely possible I'm using the wrong data model for this task, 
however I've been stumped for a couple of day on this. It took me a while 
to even figure out how to pass in unique "initial" values for each form in 
the formset.

Any recommendations would save what little hair I have left. Thank you!



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f19f3ef-7c5d-409c-98ab-150c07a196e1%40googlegroups.com.


How to create choices/options on the web page

2019-06-18 Thread mollyx09
I've been trying to create a list of options/choices for the user to choose 
from to display different types of graphs(bar/line etc) on the web page 
based on the same data that has been previously entered by me. I couldn't 
find very useful information online to go about this. Could you please help 
me out?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12fdb1a3-2a35-486f-b130-44323e78d14a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to update choices of field in change_view

2019-04-18 Thread richard . wu . 03
hi There,
I have a field named A which has default choices, but when some filed named 
B was changed, i need to update the choices of filed A.
I have tried overried function get_form, formfield_for_choice_filed, none 
of them could update choice of A based on value of filed B.

Any help would be appreciated, 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ce65f7d7-4e9c-4f98-901a-d11524318cc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Filtering choices in a form based on previous field selection

2019-04-07 Thread Gavin Boyle
Hi all,

Just quickly to summarize I have an app, which allows clubs to sign up and
carry out different tasks. One of the features is a scheduling / rosters.
Currently I have a form to add times to the roster. The club pages work off
a session key based on the initially selected club.

My form consists of:
*club_id* - which I have hidden and initialized based on the logged in user.
*pitch_id - *which is currently displaying all pitches associated to all
clubs but I need this to *only show pitches based on the foreign key for
the club_id *

Would appreciate any help.

Please see code below:

*form.py *

from django import forms
from clubkit.roster.models import RosterId
import datetime
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


# Form to add/edit club roster
class RosterForm(forms.ModelForm):

class Meta():
model = RosterId
fields = ('club_id', 'pitch_id', 'team_id', 'date',
  'start_time', 'finish_time', 'reoccuring_event',)
widgets = {
'date': forms.DateInput(attrs={'id': 'datepicker'})
}

def clean_date(self):
date = self.clean_date['date']
if date < datetime.date.today():
raise ValidationError(_('Date cannot be in the past.'))
return date

def __init__(self, *args, **kwargs):
super(RosterForm, self).__init__(*args, **kwargs)
self.fields['club_id'].widget = forms.HiddenInput()

*model.py - for roster*

from django.db import models
from clubkit.clubs.models import ClubInfo, Pitch, Team


# Model to store roster information
class RosterId(models.Model):
club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
pitch_id = models.ForeignKey(Pitch, on_delete=models.CASCADE)
team_id = models.ForeignKey(Team, on_delete=models.CASCADE)
date = models.DateField(max_length=8)
start_time = models.TimeField(default='')
finish_time = models.TimeField(default='')
reoccuring_event = models.BooleanField(default=False)

*model.py - for pitch*

class Pitch(models.Model):
club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE,
related_name="pitches")
pitch_name = models.CharField(max_length=30)
PITCH_SIZES = (
('S', 'Small'),
    ('M', 'Medium'),
('L', 'Large'),
)
PITCH_TYPE = (
('1', 'Outdoor'),
('2', 'Indoor'),
)
pitch_size = models.CharField(max_length=1, choices=PITCH_SIZES)
pitch_type = models.CharField(max_length=1, choices=PITCH_TYPE)
open_time = models.TimeField(default='09:00')
close_time = models.TimeField(default='22:00')
RENT_TYPE = (
('0', 'Not Available To Rent'),
('1', 'Available To Rent'),
)
rental = models.CharField(max_length=1, choices=RENT_TYPE)
rental_price = models.DecimalField(default=0.00, max_digits=6,
decimal_places=2)
max_people = models.IntegerField(null=True)

def __str__(self):
return self.pitch_name

*view.py*

class ClubRoster(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'roster.html'

# Get method to retrieve current roster information and form
def get(self, request):
if request.user.is_authenticated:
club_pk = request.session.get('pk')
club_info = ClubInfo.objects.filter(user=request.user).first()
reoccuring_event =
RosterId.objects.filter(reoccuring_event=True, club_id=club_pk)
inital_data = {
'club_id': club_info,
}
form = RosterForm(initial=inital_data)
roster = RosterId.objects.filter(club_id=club_pk)
return Response({'form': form,
 'roster': roster,
 'club_pk': club_pk,
 'reoccuring_event': reoccuring_event
 })

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
<https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>  
<https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
<https://www4.dcu.ie/iss/email-disclaimer.shtml> _
*_

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and

Re: Trying to filter out choices in a form based on the logged in user.

2019-02-09 Thread Ricardo Cataldi
You van create this property on your model, andam the init would bem
applied to your form

Em sáb, 9 de fev de 2019 13:15, GavinB841  Hi Ricardo,
>
> Really appreciate your reply, I am struggling to understand where I would
> create this property as I am quite new to Django and haven't worked with
> these before.
>
> Is it included in the model/view/form and under which model for the club,
> user or team.
>
> Thanks for your help.
>
> Gavin
>
> On Saturday, 9 February 2019 13:40:09 UTC, Ricardo Cataldi wrote:
>>
>> Hello there Galvin,
>>
>>
>>
>> You can create properties on the users and filter the queryset
>> conditioning to the user. It depends on how many categories of user you
>> have and how these users are supposed to be filtered by those teams.
>>
>>
>>
>> For example, if you have a spatial selection based on user location, you
>> create a property called ‘location_filter’ and set the separation rule on
>> this property, like:
>>
>>
>>
>> @property
>>
>> def location_filter(self):
>>
>> location = self.location
>>
>> filter_rule = 5miles
>>
>> return [self.location - filter_rule, self.location +
>> filter_rule]
>>
>>
>>
>> and in your form you set a init argument to query those filter rules, in
>> the fashion that you want:
>>
>>
>>
>> def __init__(self, *args, **kwargs):
>>
>> user = kwargs.pop(‘user’, None)
>>
>> self.fields[‘club_id’].queryset =
>> Club.objects.filter(place__lte=user.location_filter[1],
>> place__gte=user.location_filter[0])
>>
>>
>>
>> I have not tested this solution, but with some minor code changes it
>> should work like a charm in filtering the club queryset.
>>
>>
>>
>> *From:* django...@googlegroups.com  *On
>> Behalf Of *GavinB841
>> *Sent:* sábado, 9 de fevereiro de 2019 11:24
>> *To:* Django users 
>> *Subject:* Trying to filter out choices in a form based on the logged in
>> user.
>>
>>
>>
>> Hi all,
>>
>>
>>
>> If anyone could help or point me in the direction of some documentation
>> for the below problem I am having I would really appreciate it.
>>
>>
>>
>> Just to explain quickly:
>>
>>1. I have a model called "Team" which contains a foreign key to
>>another model called "Club"
>>2. The "Club" model contains a foreign key to the "User" model.
>>3. I have a form for the "Team" model which takes in "club_id",
>>currently it lists all the club_id for all users and I want to restrict
>>this.
>>4. I am looking to find out how I can auto-populate this field
>>"club_id" based on the logged in user, which I will then hide in the form.
>>
>> Below is my forms.py
>>
>>
>>
>> class ClubInfoForm(forms.ModelForm):
>> club_address2 = forms.CharField(required=False)
>> club_address3 = forms.CharField(required=False)
>>
>> class Meta():
>> model = ClubInfo
>> fields = ('club_name', 'club_logo', 'club_address1', 'club_address2',
>>   'club_address3', 'club_town', 'club_county', 
>> 'club_country',)
>>
>> def clean_club_name(self):
>> club_name = self.cleaned_data['club_name']
>> if ClubInfo.objects.filter(club_name=club_name).exists():
>> raise ValidationError(_("Club already exists"))
>> return club_name
>>
>>
>> class TeamForm(forms.ModelForm):
>>
>> class Meta():
>> model = Team
>> fields = ('club_id', 'team_name', 'manager_name')
>>
>> def __init__(self, *args, **kwargs):
>> super(TeamForm, self).__init__(*args, **kwargs)
>>
>>
>>
>>
>>
>> models.py
>>
>>
>>
>> class ClubInfo(models.Model):
>>
>> user = models.OneToOneField(User, on_delete=models.CASCADE)
>> club_name = models.CharField(max_length=50, default='', unique=True)
>> club_logo = models.ImageField(upload_to='profile_pics', blank=True)
>> club_address1 = models.CharField(max_length=30)
>> club_address2 = models.CharField(max_length=30, default='')
>

Re: Trying to filter out choices in a form based on the logged in user.

2019-02-09 Thread GavinB841
Hi Ricardo,

Really appreciate your reply, I am struggling to understand where I would 
create this property as I am quite new to Django and haven't worked with 
these before.

Is it included in the model/view/form and under which model for the club, 
user or team. 

Thanks for your help.

Gavin 

On Saturday, 9 February 2019 13:40:09 UTC, Ricardo Cataldi wrote:
>
> Hello there Galvin,
>
>  
>
> You can create properties on the users and filter the queryset 
> conditioning to the user. It depends on how many categories of user you 
> have and how these users are supposed to be filtered by those teams.
>
>  
>
> For example, if you have a spatial selection based on user location, you 
> create a property called ‘location_filter’ and set the separation rule on 
> this property, like:
>
>  
>
> @property
>
> def location_filter(self):
>
> location = self.location
>
> filter_rule = 5miles
>
> return [self.location - filter_rule, self.location + 
> filter_rule]
>
>  
>
> and in your form you set a init argument to query those filter rules, in 
> the fashion that you want:
>
>  
>
> def __init__(self, *args, **kwargs):
>
> user = kwargs.pop(‘user’, None)
>
> self.fields[‘club_id’].queryset = 
> Club.objects.filter(place__lte=user.location_filter[1], 
> place__gte=user.location_filter[0])
>
>  
>
> I have not tested this solution, but with some minor code changes it 
> should work like a charm in filtering the club queryset.
>
>  
>
> *From:* django...@googlegroups.com  <
> django...@googlegroups.com > *On Behalf Of *GavinB841
> *Sent:* sábado, 9 de fevereiro de 2019 11:24
> *To:* Django users >
> *Subject:* Trying to filter out choices in a form based on the logged in 
> user.
>
>  
>
> Hi all,
>
>  
>
> If anyone could help or point me in the direction of some documentation 
> for the below problem I am having I would really appreciate it.
>
>  
>
> Just to explain quickly:
>
>1. I have a model called "Team" which contains a foreign key to 
>another model called "Club"
>2. The "Club" model contains a foreign key to the "User" model.
>3. I have a form for the "Team" model which takes in "club_id", 
>currently it lists all the club_id for all users and I want to restrict 
>this.
>4. I am looking to find out how I can auto-populate this field 
>"club_id" based on the logged in user, which I will then hide in the form. 
>
> Below is my forms.py
>
>  
>
> class ClubInfoForm(forms.ModelForm):
> club_address2 = forms.CharField(required=False)
> club_address3 = forms.CharField(required=False)
>
> class Meta():
> model = ClubInfo
> fields = ('club_name', 'club_logo', 'club_address1', 'club_address2',
>   'club_address3', 'club_town', 'club_county', 
> 'club_country',)
>
> def clean_club_name(self):
> club_name = self.cleaned_data['club_name']
> if ClubInfo.objects.filter(club_name=club_name).exists():
> raise ValidationError(_("Club already exists"))
> return club_name
>
>
> class TeamForm(forms.ModelForm):
>
> class Meta():
> model = Team
> fields = ('club_id', 'team_name', 'manager_name')
>
> def __init__(self, *args, **kwargs):
> super(TeamForm, self).__init__(*args, **kwargs)
>
>  
>
>  
>
> models.py
>
>  
>
> class ClubInfo(models.Model):
>
> user = models.OneToOneField(User, on_delete=models.CASCADE)
> club_name = models.CharField(max_length=50, default='', unique=True)
> club_logo = models.ImageField(upload_to='profile_pics', blank=True)
> club_address1 = models.CharField(max_length=30)
> club_address2 = models.CharField(max_length=30, default='')
> club_address3 = models.CharField(max_length=30, default='')
> club_town = models.CharField(max_length=30)
> club_county = models.CharField(max_length=30)
> club_country = models.CharField(max_length=30)
> created_date = models.DateTimeField(default=timezone.now)
>
> def __str__(self):
> return self.club_name
>
>  
>
> class Team(models.Model):
>
> club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
> team_name = models.CharField(max_length=30)
> manager_name = models.CharField(max_l

RE: Trying to filter out choices in a form based on the logged in user.

2019-02-09 Thread Ricardo Cataldi
Hello there Galvin,

 

You can create properties on the users and filter the queryset conditioning to 
the user. It depends on how many categories of user you have and how these 
users are supposed to be filtered by those teams.

 

For example, if you have a spatial selection based on user location, you create 
a property called ‘location_filter’ and set the separation rule on this 
property, like:

 

@property

def location_filter(self):

location = self.location

filter_rule = 5miles

return [self.location - filter_rule, self.location + 
filter_rule]

 

and in your form you set a init argument to query those filter rules, in the 
fashion that you want:

 

def __init__(self, *args, **kwargs):

user = kwargs.pop(‘user’, None)

self.fields[‘club_id’].queryset = 
Club.objects.filter(place__lte=user.location_filter[1], 
place__gte=user.location_filter[0])

 

I have not tested this solution, but with some minor code changes it should 
work like a charm in filtering the club queryset.

 

From: django-users@googlegroups.com  On Behalf 
Of GavinB841
Sent: sábado, 9 de fevereiro de 2019 11:24
To: Django users 
Subject: Trying to filter out choices in a form based on the logged in user.

 

Hi all,

 

If anyone could help or point me in the direction of some documentation for the 
below problem I am having I would really appreciate it.

 

Just to explain quickly:

1.  I have a model called "Team" which contains a foreign key to another 
model called "Club"
2.  The "Club" model contains a foreign key to the "User" model.
3.  I have a form for the "Team" model which takes in "club_id", currently 
it lists all the club_id for all users and I want to restrict this.
4.  I am looking to find out how I can auto-populate this field "club_id" 
based on the logged in user, which I will then hide in the form. 

Below is my forms.py

 

class ClubInfoForm(forms.ModelForm):
club_address2 = forms.CharField(required=False)
club_address3 = forms.CharField(required=False)

class Meta():
model = ClubInfo
fields = ('club_name', 'club_logo', 'club_address1', 'club_address2',
  'club_address3', 'club_town', 'club_county', 'club_country',)

def clean_club_name(self):
club_name = self.cleaned_data['club_name']
if ClubInfo.objects.filter(club_name=club_name).exists():
raise ValidationError(_("Club already exists"))
return club_name


class TeamForm(forms.ModelForm):

class Meta():
model = Team
fields = ('club_id', 'team_name', 'manager_name')

def __init__(self, *args, **kwargs):
super(TeamForm, self).__init__(*args, **kwargs)
 
 
models.py
 
class ClubInfo(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE)
club_name = models.CharField(max_length=50, default='', unique=True)
club_logo = models.ImageField(upload_to='profile_pics', blank=True)
club_address1 = models.CharField(max_length=30)
club_address2 = models.CharField(max_length=30, default='')
club_address3 = models.CharField(max_length=30, default='')
club_town = models.CharField(max_length=30)
club_county = models.CharField(max_length=30)
club_country = models.CharField(max_length=30)
created_date = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.club_name
 
class Team(models.Model):

club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
team_name = models.CharField(max_length=30)
manager_name = models.CharField(max_length=20)


def __str__(self):
return self.team_name

 

Séanadh Ríomhphoist/

Email Disclaimer

Tá an ríomhphost seo agus aon chomhad a sheoltar leis faoi rún agus is lena 
úsáid ag an seolaí agus sin amháin é. Is féidir tuilleadh a léamh anseo. 
<https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>  
<https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>  

This e-mail and any files transmitted with it are confidential and are intended 
solely for use by the addressee. Read more here. 
<https://www4.dcu.ie/iss/email-disclaimer.shtml>  

-- 
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 
<mailto:django-users+unsubscr...@googlegroups.com> .
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com> .
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visi

Trying to filter out choices in a form based on the logged in user.

2019-02-09 Thread GavinB841
Hi all,

If anyone could help or point me in the direction of some documentation for 
the below problem I am having I would really appreciate it.

Just to explain quickly:

   1. I have a model called "Team" which contains a foreign key to another 
   model called "Club"
   2. The "Club" model contains a foreign key to the "User" model.
   3. I have a form for the "Team" model which takes in "club_id", 
   currently it lists all the club_id for all users and I want to restrict 
   this.
   4. I am looking to find out how I can auto-populate this field "club_id" 
   based on the logged in user, which I will then hide in the form. 

Below is my forms.py

class ClubInfoForm(forms.ModelForm):
club_address2 = forms.CharField(required=False)
club_address3 = forms.CharField(required=False)

class Meta():
model = ClubInfo
fields = ('club_name', 'club_logo', 'club_address1', 'club_address2',
  'club_address3', 'club_town', 'club_county', 'club_country',)

def clean_club_name(self):
club_name = self.cleaned_data['club_name']
if ClubInfo.objects.filter(club_name=club_name).exists():
raise ValidationError(_("Club already exists"))
return club_name


class TeamForm(forms.ModelForm):

class Meta():
model = Team
fields = ('club_id', 'team_name', 'manager_name')

def __init__(self, *args, **kwargs):
super(TeamForm, self).__init__(*args, **kwargs)



models.py


class ClubInfo(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE)
club_name = models.CharField(max_length=50, default='', unique=True)
club_logo = models.ImageField(upload_to='profile_pics', blank=True)
club_address1 = models.CharField(max_length=30)
club_address2 = models.CharField(max_length=30, default='')
club_address3 = models.CharField(max_length=30, default='')
club_town = models.CharField(max_length=30)
club_county = models.CharField(max_length=30)
club_country = models.CharField(max_length=30)
created_date = models.DateTimeField(default=timezone.now)

def __str__(self):
return self.club_name


class Team(models.Model):

club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
team_name = models.CharField(max_length=30)
manager_name = models.CharField(max_length=20)


def __str__(self):
return self.team_name


-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8188ff6e-bf56-4010-9caf-90d8a294a187%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to aasign id on forms.py and how to generates choices on the form of another models for individual id ,choices may be differenet for individual id

2019-01-29 Thread Suzan Bajracharya


class Medical_Meds(models.Model): medicines=models.CharField(max_length=250) 
amount=models.IntegerField(default=0) # 
is_purchase=models.BooleanField(default=False) 
p_date=models.DateTimeField(default=datetime.now) 
patient=models.ForeignKey(Patient) medical=models.ForeignKey(Medical) class 
Medical_Meds_Forms(forms.ModelForm): patient=4, opt = [] # my = 
Doctor_Patient_Med.objects.all() my = 
Doctor_Patient_Med.objects.filter(patient=patient) for x in my: 
opt.append([x.medicines,x.medicines]) total=len(opt) print(total) medicines 
=forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=opt) 
amount=forms.IntegerField(label='Amount',initial="0") 
p_date=forms.widgets.DateTimeInput(attrs={'type':'date'}) # p_date = 
forms.DateTimeField(label='Purchase-Date', 
widget=forms.DateTimeInput(attrs={'type':'date'})) class Meta: 
model=Medical_Meds exclude=['patient','doctor','medical']

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61b2f836-49db-4d1b-973f-6676a8a734b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Stodge
Thanks Simon. It's for an offline tool so high performance isn't the top 
priority.

On Monday, 10 December 2018 11:56:53 UTC-5, Simon Charette wrote:
>
> Given choices are defined at the module level I guess you could
> iterate over objects defined in each `sys.modules` (or the ones
> likely to define choices) and use the `is` operator to compare all
> of them to the field choices.
>
> This will perform badly and shouldn't be used for anything else
> than one off debugging reflection though.
>
> Best,
> Simon
>
> Le lundi 10 décembre 2018 10:33:35 UTC-5, Stodge a écrit :
>>
>> Let's say I take the following code from the Django documentatation:
>>
>>
>> class Student(models.Model):
>> FRESHMAN = 'FR'
>> SOPHOMORE = 'SO'
>> JUNIOR = 'JR'
>> SENIOR = 'SR'
>> YEAR_IN_SCHOOL_CHOICES = (
>> (FRESHMAN, 'Freshman'),
>> (SOPHOMORE, 'Sophomore'),
>> (JUNIOR, 'Junior'),
>> (SENIOR, 'Senior'),
>> )
>>     year_in_school = models.CharField(
>> max_length=2,
>> choices=YEAR_IN_SCHOOL_CHOICES,
>> default=FRESHMAN,
>> )
>>
>>
>> But instead I want to do:
>>
>> from student_app import choices
>>     class Student(models.Model):
>> year_in_school = models.CharField(
>> max_length=2,
>> choices=choices.YEAR_IN_SCHOOL_CHOICES,
>>     default=choices.FRESHMAN,
>> )
>>
>>
>> Is there anyway using reflection to determine which module the choices 
>> are imported from?
>>
>> For example:
>>
>> field = Student._meta.fields.get_field_by_name('year_in_school')
>> choices_source = some_clever_function(field)
>> print("Choices imported from %s." % choices_source)
>>
>> I want the output to be:
>>
>> Choices imported from student_app.
>>
>> Obviously the clever function does not exist but hopefully clarifies what 
>> I'm trying to do.
>>
>> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8293ea73-1eae-4dcf-880a-64c55f051a12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Simon Charette
Given choices are defined at the module level I guess you could
iterate over objects defined in each `sys.modules` (or the ones
likely to define choices) and use the `is` operator to compare all
of them to the field choices.

This will perform badly and shouldn't be used for anything else
than one off debugging reflection though.

Best,
Simon

Le lundi 10 décembre 2018 10:33:35 UTC-5, Stodge a écrit :
>
> Let's say I take the following code from the Django documentatation:
>
>
> class Student(models.Model):
> FRESHMAN = 'FR'
> SOPHOMORE = 'SO'
> JUNIOR = 'JR'
> SENIOR = 'SR'
> YEAR_IN_SCHOOL_CHOICES = (
> (FRESHMAN, 'Freshman'),
> (SOPHOMORE, 'Sophomore'),
> (JUNIOR, 'Junior'),
>     (SENIOR, 'Senior'),
> )
> year_in_school = models.CharField(
> max_length=2,
> choices=YEAR_IN_SCHOOL_CHOICES,
> default=FRESHMAN,
> )
>
>
> But instead I want to do:
>
> from student_app import choices
> class Student(models.Model):
> year_in_school = models.CharField(
> max_length=2,
> choices=choices.YEAR_IN_SCHOOL_CHOICES,
> default=choices.FRESHMAN,
> )
>
>
> Is there anyway using reflection to determine which module the choices are 
> imported from?
>
> For example:
>
> field = Student._meta.fields.get_field_by_name('year_in_school')
> choices_source = some_clever_function(field)
> print("Choices imported from %s." % choices_source)
>
> I want the output to be:
>
> Choices imported from student_app.
>
> Obviously the clever function does not exist but hopefully clarifies what 
> I'm trying to do.
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4e74fd89-715a-4b93-bbe9-7d0bcd50fe98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Stodge
Let's say I take the following code from the Django documentatation:


class Student(models.Model):
FRESHMAN = 'FR'
SOPHOMORE = 'SO'
JUNIOR = 'JR'
SENIOR = 'SR'
YEAR_IN_SCHOOL_CHOICES = (
(FRESHMAN, 'Freshman'),
(SOPHOMORE, 'Sophomore'),
(JUNIOR, 'Junior'),
(SENIOR, 'Senior'),
    )
    year_in_school = models.CharField(
max_length=2,
choices=YEAR_IN_SCHOOL_CHOICES,
default=FRESHMAN,
)


But instead I want to do:

from student_app import choices
class Student(models.Model):
    year_in_school = models.CharField(
max_length=2,
choices=choices.YEAR_IN_SCHOOL_CHOICES,
default=choices.FRESHMAN,
)


Is there anyway using reflection to determine which module the choices are 
imported from?

For example:

field = Student._meta.fields.get_field_by_name('year_in_school')
choices_source = some_clever_function(field)
print("Choices imported from %s." % choices_source)

I want the output to be:

Choices imported from student_app.

Obviously the clever function does not exist but hopefully clarifies what 
I'm trying to do.

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/78f7dcc2-c822-42cc-a06a-860ae080e5b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: using a foreign key with multiple choices

2018-11-13 Thread Jani Tiainen
Well categoriederecette is a foereign key to your Categorie model.

Your models don't make any real sense.

If your categories are fixed you can remove foreign key and add charfield
and definitions directly to Recette model.

If you expect that categories are added, changed, created or deleted
frequently having your current structure is okayish. Just make a name field
in Categorie model as free text.

'Christian' via Django users  kirjoitti ti
13. marrask. 2018 klo 14.45:

> Hello
>
> I need to use a model form to create a new instance of Recette,  using
> multiple choices list instead of the foreign_key
>
> *class Recette(models.Model):*
> *  ..*
> *categoriederecette = models.ForeignKey(Categorie,
> on_delete=models.CASCADE) *
>
> *class Categorie(models.Model):*
> *SOUPE = 'SP'*
> *DESSERTS ='DS'*
> *PLATUNIQUE ='PU'*
> *LISTE_CHOIX =  ((SOUPE,'Soupe'), (DESSERTS,'Desserts'),
> (PLATUNIQUE,'Plat unique'),)*
> *   .*
> *categorierecette = models.CharField(db_column='Categorierecette',
> max_length=15, choices=LISTE_CHOIX, blank=True, null=True)  # Field name
> made lowercase*
>
> I use a Modelform
> * : *
>
> *class RecettesForm(forms.ModelForm):*
> *categoriederecette = forms.ChoiceField(choices =
> Categorie.LISTE_CHOIX)*
>
> *class Meta:*
> *model = Recette*
> *fields = (..** ,'categoriederecette')*
>
>
> The form is displayed correctly,  but cannot be saved. In the test *if
> form.is_valid():*  I get a value error -
>
> * ValueError: Cannot assign "'SP'": "Recette.categoriederecette" must be a
> "Categorie" instance.*
>
> Any help would be greatly appreciated.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/524c62ab-2454-7746-ec6a-9c7daeed775d%40yahoo.fr
> <https://groups.google.com/d/msgid/django-users/524c62ab-2454-7746-ec6a-9c7daeed775d%40yahoo.fr?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91of2kF6XJFx--5iJMsx%3D-1jHdQ2pxoHxNwNHyjp%3Dm9jWEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: using a foreign key with multiple choices

2018-11-13 Thread amit pant
use dict in  * LISTE_CHOIX.*

On Tue, Nov 13, 2018 at 6:14 PM 'Christian' via Django users <
django-users@googlegroups.com> wrote:

> Hello
>
> I need to use a model form to create a new instance of Recette,  using
> multiple choices list instead of the foreign_key
>
> *class Recette(models.Model):*
> *  ..*
> *categoriederecette = models.ForeignKey(Categorie,
> on_delete=models.CASCADE) *
>
> *class Categorie(models.Model):*
> *SOUPE = 'SP'*
> *DESSERTS ='DS'*
> *PLATUNIQUE ='PU'*
> *LISTE_CHOIX =  ((SOUPE,'Soupe'), (DESSERTS,'Desserts'),
> (PLATUNIQUE,'Plat unique'),)*
> *   .*
> *categorierecette = models.CharField(db_column='Categorierecette',
> max_length=15, choices=LISTE_CHOIX, blank=True, null=True)  # Field name
> made lowercase*
>
> I use a Modelform
> * : *
>
> *class RecettesForm(forms.ModelForm):*
> *categoriederecette = forms.ChoiceField(choices =
> Categorie.LISTE_CHOIX)*
>
> *class Meta:*
> *model = Recette*
> *fields = (..** ,'categoriederecette')*
>
>
> The form is displayed correctly,  but cannot be saved. In the test *if
> form.is_valid():*  I get a value error -
>
> * ValueError: Cannot assign "'SP'": "Recette.categoriederecette" must be a
> "Categorie" instance.*
>
> Any help would be greatly appreciated.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/524c62ab-2454-7746-ec6a-9c7daeed775d%40yahoo.fr
> <https://groups.google.com/d/msgid/django-users/524c62ab-2454-7746-ec6a-9c7daeed775d%40yahoo.fr?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF2Ah_E2UnvGgt2G%3DZ1ECc2wvnaWPH32da5h%2BXxZhsgtjprHpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


using a foreign key with multiple choices

2018-11-13 Thread 'Christian' via Django users

Hello

I need to use a model form to create a new instance of Recette, using 
multiple choices list instead of the foreign_key


/class Recette(models.Model)://
//  ..//
//    categoriederecette = models.ForeignKey(Categorie, 
on_delete=models.CASCADE) //

/

/class Categorie(models.Model)://
//    SOUPE = 'SP'//
//    DESSERTS ='DS'//
//    PLATUNIQUE ='PU'//
//    LISTE_CHOIX =  ((SOUPE,'Soupe'), (DESSERTS,'Desserts'), 
(PLATUNIQUE,'Plat unique'),)//

//   .//
//    categorierecette = models.CharField(db_column='Categorierecette', 
max_length=15, choices=LISTE_CHOIX, blank=True, null=True)  # Field name 
made lowercase/


I use a Modelform/:
/

/class RecettesForm(forms.ModelForm)://
//    categoriederecette = forms.ChoiceField(choices = 
Categorie.LISTE_CHOIX)//


//    class Meta://
//    model = Recette//
//    fields = (..//,'categoriederecette')/

/
/

The form is displayed correctly,  but cannot be saved. In the test /if 
form.is_valid():/  I get a value error -


/ValueError: Cannot assign "'SP'": "Recette.categoriederecette" must be 
a "Categorie" instance./


Any help would be greatly appreciated.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/524c62ab-2454-7746-ec6a-9c7daeed775d%40yahoo.fr.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter choices in Django2's autocomplete_fields?

2018-08-29 Thread ciaran . courtney
Not possible ATM it seems, pity https://code.djangoproject.com/ticket/29010

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7492c86-2a3e-4d29-9add-b90f5284b718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter choices in Django2's autocomplete_fields?

2018-08-29 Thread ciaran . courtney
You need to override  ModelAdmin.get_search_results()  as per 
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields

My problem is I override ForeignKeyField in AdminForm, where I can filter 
based on self.instance, this is not possible in current implementation 
AFAICS? The instance ID would have to be passed to the autocomplete_view

On Monday, 8 January 2018 16:49:56 UTC, Oren wrote:
>
> In Django 2.0, autocomplete_fields 
> 
>  was 
> added, which is great.
>
> Without autocomplete_fields, I can change the queryset of a 
> ForeignKeyField using formfield_for_foreignkey 
> 
> .
>
> But combining the two together doesn't work - it looks like the list of 
> options for autocomplete is dynamic and coming from a different url, 
> instead of from the current form.
>
> So the question is -
>
> How can I change the queryset in the autocomplete widget?
> Thanks,
> Oren
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f1b313c-82d6-454d-ba4e-85d7bbaa01c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django model's field dynamic choices

2018-05-14 Thread Marcin
I'm using Django 1.11. I cannot set dynamic choices for model's field 
because:

   - choices must be iterable, not function,
   - choices iterable is always coverted to list,
   - iterable is evaluated oat the module import stage.


The whole thing is about iterable evaluation time. The data source is 
populated once at App.ready() stage, after models.py imports. 
This results in empty choices, always. It is a big limitation. 

I do not understand why Django supports custom iterators if they're always 
converted to lists so early.

How to achieve dynamic choices at the model level? Any ideas? Thanks.

BR,
M

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0e7207e-9cdb-40fd-bef3-e726630616e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I get dynamic choices to a select widget at render time?

2018-02-22 Thread Mike Dewhirst

On 20/02/2018 11:51 PM, Andy wrote:

use django-select2


Had a look at the docs and django-select2 doesn't address this use case. 
However, I can see I will need it for ORM related selections in the near 
term.


Thanks Andy.



Am Dienstag, 20. Februar 2018 01:17:26 UTC+1 schrieb Mike Dewhirst:

Here is an example of get_choices() output ... it comes from a
method on
the Question model.

  [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'),
('D', 'D - Twelve times?'), ('E', 'E - Continously as changes are
made?')]

It is available before the the answer form is instantiated ...

class AnswerSingleForm(forms.ModelForm):

 class Meta:
 model = Answer
 fields = [
     'answer',
 'score'
 ]

So how do I get that set of choices into the Answer form?

I can see from the docs that the form Meta class can have a widgets
attribute for the 'answer' field. I think I need a ChoiceField
widget so
I can include the choices. I tried using __init__() in the form
class to
get the choices on board at instantiation but still couldn't get it
going because class Meta doesn't see 'self'.

Thanks for any help

Stumped

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com>.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4eaf732e-54c5-4e43-ba6e-8ef72c999c90%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/4eaf732e-54c5-4e43-ba6e-8ef72c999c90%40googlegroups.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/57e176e3-4a74-ddaa-47f0-ac85873b14b3%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How do I get dynamic choices to a select widget at render time?

2018-02-20 Thread Andy
use django-select2

Am Dienstag, 20. Februar 2018 01:17:26 UTC+1 schrieb Mike Dewhirst:
>
> Here is an example of get_choices() output ... it comes from a method on 
> the Question model. 
>
>   [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'), 
> ('D', 'D - Twelve times?'), ('E', 'E - Continously as changes are made?')] 
>
> It is available before the the answer form is instantiated ... 
>
> class AnswerSingleForm(forms.ModelForm): 
>
>  class Meta: 
>  model = Answer 
>  fields = [ 
>  'answer', 
>  'score' 
>  ] 
>
> So how do I get that set of choices into the Answer form? 
>
> I can see from the docs that the form Meta class can have a widgets 
> attribute for the 'answer' field. I think I need a ChoiceField widget so 
> I can include the choices. I tried using __init__() in the form class to 
> get the choices on board at instantiation but still couldn't get it 
> going because class Meta doesn't see 'self'. 
>
> Thanks for any help 
>
> Stumped 
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4eaf732e-54c5-4e43-ba6e-8ef72c999c90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I get dynamic choices to a select widget at render time?

2018-02-20 Thread Mike Dewhirst

On 20/02/2018 11:16 AM, Mike Dewhirst wrote:
Here is an example of get_choices() output ... it comes from a method 
on the Question model.


 [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'), 
('D', 'D - Twelve times?'), ('E', 'E - Continously as changes are 
made?')]


It is available before the the answer form is instantiated ...

class AnswerSingleForm(forms.ModelForm):

    class Meta:
    model = Answer
    fields = [
    'answer',
    'score'
    ]



This is my new form which seems to work ...

class AnswerSingleForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):

    super(AnswerSingleForm, self).__init__(*args, **kwargs)

    answer = kwargs['instance']

    choices = answer.question.get_choices()

    if len(choices) > 0:

    self.fields['answer'] = forms.ChoiceField(

    choices=choices

    )

    class Meta:

    model = Answer

    fields = [

    'answer',

    'score'

    ]










So how do I get that set of choices into the Answer form?

I can see from the docs that the form Meta class can have a widgets 
attribute for the 'answer' field. I think I need a ChoiceField widget 
so I can include the choices. I tried using __init__() in the form 
class to get the choices on board at instantiation but still couldn't 
get it going because class Meta doesn't see 'self'.


Thanks for any help

Stumped



--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8a7fbe08-214e-745e-15ee-89303ea7a774%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


How do I get dynamic choices to a select widget at render time?

2018-02-19 Thread Mike Dewhirst
Here is an example of get_choices() output ... it comes from a method on 
the Question model.


 [('A', 'A - Once?'), ('B', 'B - Twice?'), ('C', 'C - Four times?'), 
('D', 'D - Twelve times?'), ('E', 'E - Continously as changes are made?')]


It is available before the the answer form is instantiated ...

class AnswerSingleForm(forms.ModelForm):

    class Meta:
    model = Answer
    fields = [
    'answer',
    'score'
    ]

So how do I get that set of choices into the Answer form?

I can see from the docs that the form Meta class can have a widgets 
attribute for the 'answer' field. I think I need a ChoiceField widget so 
I can include the choices. I tried using __init__() in the form class to 
get the choices on board at instantiation but still couldn't get it 
going because class Meta doesn't see 'self'.


Thanks for any help

Stumped

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0784c79f-81fb-6a88-b7f6-cbdbcec552fe%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How to do "choices" from DB in form field without breaking migrations and such

2018-02-15 Thread C Kirby
Yeah, I meant to write about that. If you put a database filter in a field
definition (model or form) it only runs it on start/restart. Using the
method I put, or a callback function in the choices, allows the choices to
reflect reality of the data.

On Thu, Feb 15, 2018 at 12:24 PM,  wrote:

> Thank you very much.  This worked perfectly.  Consequently it also fixed
> my issue of those select boxes not reflecting changes in the list until the
> web server was restarted since the data is now being pulled at
> instantiation instead of in the class definition.
>
> j
>
>
>
> On Thursday, February 15, 2018 at 9:54:24 AM UTC-6, C. Kirby wrote:
>>
>> You can set the choices in the form __init__ to handle the issue:
>>
>>  class FooJBossForm(Form):
>> biz_service = MultipleChoiceField(
>> choices=[],
>> required=False,
>> label='Business Service',
>> widget=SelectMultiple(attrs={'class': 'form-control'}),
>> )
>>
>> def __init__(self, *args, **kwargs):
>> super(FooJBossForm, self).__init__(*args, **kwargs)
>> try:
>> self.fields['biz_service'].choices =
>> BizService.objects.filter(
>>biz_unit__bu_name='Foo',
>>  ).order_by('bs_name')\
>>
>> .values_list('bs_name', 'bs_name')\
>>   .distinct()
>> except ProgrammingError:
>> pass #OR Some placeholder choices
>>
>> Kirby
>>
>>
>>
>> On Thursday, February 15, 2018 at 9:56:56 AM UTC-5, jason...@gmail.com
>> wrote:
>>>
>>> Hello everyone,
>>>
>>> I have a form field that is pulling choices from the database:
>>>
>>> class FooJBossForm(Form):
>>> biz_service = MultipleChoiceField(
>>> choices=BizService.objects.filter(
>>> biz_unit__bu_name='Foo',
>>> ).order_by('bs_name').values_list('bs_name', 'bs_name').distinct
>>> (),
>>> required=False,
>>> label='Business Service',
>>> widget=SelectMultiple(attrs={'class': 'form-control'}),
>>> )
>>>
>>> ...
>>>
>>> This worked great until someone else on my team attempted to start with
>>> a fresh DB and was getting "relation does not exist" errors trying to do
>>> the initial import.
>>>
>>> Commenting out these "choices=" parameters in `forms.py` fixes the
>>> issue.  What's the right way to go about populating form field choices from
>>> the DB at access time?
>>>
>>> Thanks,
>>>
>>> j
>>>
>>>
>>>
>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/4DbSczJGJF4/unsubscribe.
> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ff2289b7-630b-4132-8d48-0ffc98715cdc%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ff2289b7-630b-4132-8d48-0ffc98715cdc%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFRq707a4YnfQ8vpdvq0AB3qYTuQmFaZQCXTKE-Z8AZyAscHZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to do "choices" from DB in form field without breaking migrations and such

2018-02-15 Thread jasonbnance
Thank you very much.  This worked perfectly.  Consequently it also fixed my 
issue of those select boxes not reflecting changes in the list until the 
web server was restarted since the data is now being pulled at 
instantiation instead of in the class definition.

j


On Thursday, February 15, 2018 at 9:54:24 AM UTC-6, C. Kirby wrote:
>
> You can set the choices in the form __init__ to handle the issue:
>
>  class FooJBossForm(Form):
> biz_service = MultipleChoiceField(
> choices=[],
> required=False,
> label='Business Service',
> widget=SelectMultiple(attrs={'class': 'form-control'}),
> )
>
> def __init__(self, *args, **kwargs):
> super(FooJBossForm, self).__init__(*args, **kwargs)
> try:
> self.fields['biz_service'].choices = BizService.objects.filter(
>biz_unit__bu_name='Foo',
>  ).order_by('bs_name')\
>   .values_list('bs_name', 
> 'bs_name')\
>   .distinct()
> except ProgrammingError:
> pass #OR Some placeholder choices
>
> Kirby
>
>
>
> On Thursday, February 15, 2018 at 9:56:56 AM UTC-5, jason...@gmail.com 
> wrote:
>>
>> Hello everyone,
>>
>> I have a form field that is pulling choices from the database:
>>
>> class FooJBossForm(Form):
>> biz_service = MultipleChoiceField(
>> choices=BizService.objects.filter(
>> biz_unit__bu_name='Foo',
>> ).order_by('bs_name').values_list('bs_name', 'bs_name').distinct
>> (),
>> required=False,
>> label='Business Service',
>> widget=SelectMultiple(attrs={'class': 'form-control'}),
>> )
>>
>> ...
>>
>> This worked great until someone else on my team attempted to start with a 
>> fresh DB and was getting "relation does not exist" errors trying to do the 
>> initial import.
>>
>> Commenting out these "choices=" parameters in `forms.py` fixes the 
>> issue.  What's the right way to go about populating form field choices from 
>> the DB at access time?
>>
>> Thanks,
>>
>> j
>>
>>
>>
>>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff2289b7-630b-4132-8d48-0ffc98715cdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to do "choices" from DB in form field without breaking migrations and such

2018-02-15 Thread C. Kirby
You can set the choices in the form __init__ to handle the issue:

 class FooJBossForm(Form):
biz_service = MultipleChoiceField(
choices=[],
required=False,
label='Business Service',
widget=SelectMultiple(attrs={'class': 'form-control'}),
)

def __init__(self, *args, **kwargs):
super(FooJBossForm, self).__init__(*args, **kwargs)
try:
    self.fields['biz_service'].choices = BizService.objects.filter(
   biz_unit__bu_name='Foo',
 ).order_by('bs_name')\
  .values_list('bs_name', 
'bs_name')\
  .distinct()
except ProgrammingError:
pass #OR Some placeholder choices

Kirby



On Thursday, February 15, 2018 at 9:56:56 AM UTC-5, jason...@gmail.com 
wrote:
>
> Hello everyone,
>
> I have a form field that is pulling choices from the database:
>
> class FooJBossForm(Form):
> biz_service = MultipleChoiceField(
> choices=BizService.objects.filter(
> biz_unit__bu_name='Foo',
> ).order_by('bs_name').values_list('bs_name', 'bs_name').distinct
> (),
> required=False,
> label='Business Service',
> widget=SelectMultiple(attrs={'class': 'form-control'}),
> )
>
> ...
>
> This worked great until someone else on my team attempted to start with a 
> fresh DB and was getting "relation does not exist" errors trying to do the 
> initial import.
>
> Commenting out these "choices=" parameters in `forms.py` fixes the issue.  
> What's the right way to go about populating form field choices from the DB 
> at access time?
>
> Thanks,
>
> j
>
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9a66087-72e5-4540-b717-bbb375f116da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to do "choices" from DB in form field without breaking migrations and such

2018-02-15 Thread jasonbnance
I should have included that the reason I'm using a `MultipleChoiceField` 
instead of a `ModelMultipleChoiceField` here is because I want the POSTed 
variable to be the business service name (string) not the primary key of 
the selected record.

j


On Thursday, February 15, 2018 at 8:56:56 AM UTC-6, jason...@gmail.com 
wrote:
>
> Hello everyone,
>
> I have a form field that is pulling choices from the database:
>
> class FooJBossForm(Form):
> biz_service = MultipleChoiceField(
> choices=BizService.objects.filter(
> biz_unit__bu_name='Foo',
> ).order_by('bs_name').values_list('bs_name', 'bs_name').distinct
> (),
> required=False,
> label='Business Service',
> widget=SelectMultiple(attrs={'class': 'form-control'}),
> )
>
> ...
>
> This worked great until someone else on my team attempted to start with a 
> fresh DB and was getting "relation does not exist" errors trying to do the 
> initial import.
>
> Commenting out these "choices=" parameters in `forms.py` fixes the issue.  
> What's the right way to go about populating form field choices from the DB 
> at access time?
>
> Thanks,
>
> j
>
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2fec400e-e20b-4030-acd5-9b1e2f9db6ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to do "choices" from DB in form field without breaking migrations and such

2018-02-15 Thread jasonbnance
Hello everyone,

I have a form field that is pulling choices from the database:

class FooJBossForm(Form):
biz_service = MultipleChoiceField(
choices=BizService.objects.filter(
biz_unit__bu_name='Foo',
).order_by('bs_name').values_list('bs_name', 'bs_name').distinct(),
required=False,
label='Business Service',
widget=SelectMultiple(attrs={'class': 'form-control'}),
)

...

This worked great until someone else on my team attempted to start with a 
fresh DB and was getting "relation does not exist" errors trying to do the 
initial import.

Commenting out these "choices=" parameters in `forms.py` fixes the issue.  
What's the right way to go about populating form field choices from the DB 
at access time?

Thanks,

j



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a13f34ed-c8e9-4a92-829b-207e8eff4cf5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to filter choices in Django2's autocomplete_fields?

2018-01-08 Thread Oren


In Django 2.0, autocomplete_fields 

 was 
added, which is great.

Without autocomplete_fields, I can change the queryset of a ForeignKeyField 
using formfield_for_foreignkey 

.

But combining the two together doesn't work - it looks like the list of 
options for autocomplete is dynamic and coming from a different url, 
instead of from the current form.

So the question is -

How can I change the queryset in the autocomplete widget?
Thanks,
Oren

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd9c8a90-e1f8-47d1-af0a-a110a0b14846%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MultipleChoiceField records down choices as a list, but CharField converts them to a list?

2017-10-30 Thread James Schneider
On Thu, Oct 26, 2017 at 7:54 AM, Jack  wrote:

> I have a model field for choosing multiple options.  Here is the code for
> models and forms:
>
> *models.py:*
> CONDO_APARTMENT = 'Condo Apartment'
> DETACHED_HOUSE = 'Detached House'
> SEMI_DETACHED = 'Semi-detached'
> TOWNHOUSE = 'Townhouse'
>
> PROPERTY_TYPE = (
> (CONDO_APARTMENT, 'Condo Apartment'),
> (DETACHED_HOUSE, 'Detached House'),
> (SEMI_DETACHED, 'Semi-detached'),
> (TOWNHOUSE, 'Townhouse'),
> )
>
> property_type = models.CharField(max_length=50, help_text="You can
> select more than 1 option")
>
>
> *forms.py:*
> property_type = forms.MultipleChoiceField(widget=forms.SelectMultiple,
> choices=BuyerListing.PROPERTY_TYPE)
>
>
> Let's assume the selected choices were 'Condo Apartment' and
> 'Semi-detached'.  The value stored on my database is this - ['Condo
> Apartment', 'Semi-detached']
>


Given your model definition, that means that a Python list object was
converted to a string and stored in a single database field, which means
that you no longer have a list, you have a Python string that looks like a
list.

If your model can have multiple values associated to a single object for a
single field, consider a M2M relationship with a table containing all of
the available options.



>
> Now this is in a list format, which makes sense, but it seems to have been
> converted to a string.  When I try to call on property_type in a .html
> document...
>
> {% for property in model.property_type %}
> {{ property }}
> {% endfor %}
>


This is slightly confusing. Is 'model' a context variable that you are
providing in your view? I'm assuming this refers to the object being pulled
from the DB. If that's the case, then this code is roughly equivalent to
the following:

for x in "['Condo ap'":
print(x)


You likely just need {{ model.property_type }} given your model definition.



>
> The result is displayed in singular characters, like this:
>
> [
> '
> C
> o
> n
> d
> o
>
> a
> p
>


Happens a lot in templates when they go too deep with the {% for %} tags.



> .. and so on.  Instead I want the result to be the values in the list,
> like this:
>
> Condo apartment
> Semi-detached
>
> How do I do this?  I tried experimenting with different model field types
> but CharField seems like the only appropriate one for MultipleChoiceField.
>


I think you're intermixing Model fields and Form fields, both of which have
very different functions. I did the same thing when I first started with
Django:

https://docs.djangoproject.com/en/1.11/ref/models/fields/
https://docs.djangoproject.com/en/1.11/ref/forms/fields/

These are not interchangeable as they have different purposes.

It's not necessarily clear what you are trying to do. Your template code
indicates one thing, and your textual description another.

According to your template code, you are simply displaying a static
unordered list of text blurbs on the page, no form elements involved. From
your other descriptions,  you are trying to display a select form control
with multiple options in it. A bit more guidance here would result in a
better answer.

-James

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVDYn%2B1x4%2BF3bDu1rc%2B0pbj%2BVyZFtUXGJm9inNdZ6i2rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Building a search form with 4 required choices, which will be inserted as arguments in an URL [warning: long question]

2017-10-29 Thread Jack
That makes much more sense.  It's my fault for not reading the Django docs 
properly, but I don't seem to soak in the concepts at all by simply 
reading.  

I went with a ListView + get_queryset override.  I haven't managed to get 
the filter to work but the search itself is working properly.

Thanks Daniel!

On Sunday, October 29, 2017 at 7:59:25 AM UTC-4, Daniel Roseman wrote:
>
> On Monday, 23 October 2017 16:59:36 UTC+1, Jack wrote:
>>
>> This is a semi-long question.  Please let me know wherever I make a 
>> mistake.
>>
>> I'm building a search form with 4 required choices, 1 of the choices is a 
>> CharField with a max_length of 3.  The other 3 choices are ChoiceField's.  
>> Here is a picture of what the search form looks like:
>>
>>
>> <https://lh3.googleusercontent.com/-8GREjIuYfMc/We4LXpdGMtI/CeI/lF08A9M1zj4gL3saaVvKY9rWZ4APYU4EACLcBGAs/s1600/Capture.PNG>
>>
>> I've read through the Django docs and other things on the Internet but 
>> I'm still very unclear about how to approach this.
>>
>> 1. First I believe I need to create 4 args or kwargs in the url for each 
>> of the choices.  If I use args, it would look something like...
>>
>> url(r'^search?(\w+{3})&(\w+{2})&(\w+{1-2})&(\w+{1-2})', function/class 
>> view, name='search')
>>
>> 2. Next, I need to pass the user's input in the html page into the url 
>> args.  I have a form set up to get the user's input.  But how would I write 
>> this on the HTML page?  Do I simply make a url tag like {% url 'search' 
>> args1, args2, args3, args4 %}?
>>
>> 3. Then I need to create the views function.  My first question is, 
>> should I use a function-based view or the generic class-based ListView?  
>> The result of the search will be a list of items, so ListView is a good 
>> template to use, but I don't know how having 4 args would affect using 
>> ListView.  My second question is, what is the most effective way of making 
>> this search?  I need to check if any records in the database matches the 
>> user's search, so would I do something like 'For record in database' to 
>> check over every record in the database?
>>
>> If I used a function view, would it look something like:
>>
>> def search(request, args1, args2, args3, args4):
>>  for record in database:
>>   if args matches record:
>>display record
>>
>> Thank you for reading through the question
>>
>
>
> Your difficulties all stem from the same misunderstanding here.
>
> Forms - at least when using the GET action - put their arguments in the 
> querystring - the bit after the ? in the URL. Django doesn't treat that as 
> part of the URL itself, but as a separate attribute, `request.GET`. So both 
> your first and second questions are irrelevant: you don't need to capture 
> the values in a URL pattern, and nor do you need to insert them in there in 
> the HTML somehow. Just use a basic pattern of `r('^search/$)` and all will 
> be fine.
>
> For your third question, it makes no difference whether you use function 
> or class-based views. If you did use a ListView, though, you could override 
> `get_queryset` to filter by the values in the GET dictionary:
>
> def get_queryset(self):
> qs = super(MyListView, self).get_queryset()
> if 'bedrooms' in request.GET:
> qs = qs.filter(bedrooms=request.GET['bedrooms']
> ... etc ...
> return qs
>
> -- 
> DR.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6bb83c1-16fd-4375-88ba-9516a9677c29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Building a search form with 4 required choices, which will be inserted as arguments in an URL [warning: long question]

2017-10-29 Thread Daniel Roseman
On Monday, 23 October 2017 16:59:36 UTC+1, Jack wrote:
>
> This is a semi-long question.  Please let me know wherever I make a 
> mistake.
>
> I'm building a search form with 4 required choices, 1 of the choices is a 
> CharField with a max_length of 3.  The other 3 choices are ChoiceField's.  
> Here is a picture of what the search form looks like:
>
>
> <https://lh3.googleusercontent.com/-8GREjIuYfMc/We4LXpdGMtI/CeI/lF08A9M1zj4gL3saaVvKY9rWZ4APYU4EACLcBGAs/s1600/Capture.PNG>
>
> I've read through the Django docs and other things on the Internet but I'm 
> still very unclear about how to approach this.
>
> 1. First I believe I need to create 4 args or kwargs in the url for each 
> of the choices.  If I use args, it would look something like...
>
> url(r'^search?(\w+{3})&(\w+{2})&(\w+{1-2})&(\w+{1-2})', function/class 
> view, name='search')
>
> 2. Next, I need to pass the user's input in the html page into the url 
> args.  I have a form set up to get the user's input.  But how would I write 
> this on the HTML page?  Do I simply make a url tag like {% url 'search' 
> args1, args2, args3, args4 %}?
>
> 3. Then I need to create the views function.  My first question is, should 
> I use a function-based view or the generic class-based ListView?  The 
> result of the search will be a list of items, so ListView is a good 
> template to use, but I don't know how having 4 args would affect using 
> ListView.  My second question is, what is the most effective way of making 
> this search?  I need to check if any records in the database matches the 
> user's search, so would I do something like 'For record in database' to 
> check over every record in the database?
>
> If I used a function view, would it look something like:
>
> def search(request, args1, args2, args3, args4):
>  for record in database:
>   if args matches record:
>display record
>
> Thank you for reading through the question
>


Your difficulties all stem from the same misunderstanding here.

Forms - at least when using the GET action - put their arguments in the 
querystring - the bit after the ? in the URL. Django doesn't treat that as 
part of the URL itself, but as a separate attribute, `request.GET`. So both 
your first and second questions are irrelevant: you don't need to capture 
the values in a URL pattern, and nor do you need to insert them in there in 
the HTML somehow. Just use a basic pattern of `r('^search/$)` and all will 
be fine.

For your third question, it makes no difference whether you use function or 
class-based views. If you did use a ListView, though, you could override 
`get_queryset` to filter by the values in the GET dictionary:

def get_queryset(self):
qs = super(MyListView, self).get_queryset()
if 'bedrooms' in request.GET:
qs = qs.filter(bedrooms=request.GET['bedrooms']
... etc ...
return qs

-- 
DR.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1105250e-4811-46b2-b3a1-f25cb9af68a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible Bug Regarding model choices and form hidden input?

2017-10-28 Thread Jani Tiainen
Hi.

Unfortunately 1.7 is unsupported version.

You should test with 1.11 to see if issue still exist.

28.10.2017 18.03 "Paul Kenjora"  kirjoitti:

> *I use: *
>
> Django version 1.7.0 - I know I know :)
>
> Python 2.7.13
>
> - Paul
>
> On Sat, Oct 28, 2017 at 6:01 AM, Etienne Robillard 
> wrote:
>
>> Which Python and Django versions do you use?
>>
>> Etienne
>>
>> Le 2017-10-27 à 23:27, Paul Kenjora a écrit :
>>
>> Hi,
>>
>>   When setting HiddenInput on a form widget for an integer model field
>> with choices, in tests I get 'X is not a valid choice' errors.  I'm
>> guessing it's the hidden input returning a STRING and the model expecting
>> an INT.
>>
>>   I have a model that has
>>
>>
>> *class Banner(models.Model): *
>>
>> *  banner_x = models.PositiveIntegerField(blank=False, default=0,
>> choices=enumerate(BANNER_XS))*
>>
>>
>> And a form that has
>>
>> *class BannerForm(forms.ModelForm):*
>>
>> *  class Meta:*
>>
>> *model = Banner*
>>
>> *fields = ['banner_x']*
>>
>> *  def __init__(self, *args, **kwargs):*
>>
>> *kwargs['prefix'] = 'banner'*
>>
>> *super(BannerForm, self).__init__(*args, **kwargs)*
>>
>> *self.fields['banner_x'].widget = forms.HiddenInput()*
>>
>>
>> In my unit tests I always get the error:
>>
>> *resp = self.client.post(**'/banner/, {*
>>
>> *  'banner-banner_x':0,*
>>
>>
>> *}, follow=True) *
>>
>> *banner_xSelect a
>> valid choice. 0 is not one of the available choices.*
>>
>>
>> Anyone else seeing this?  Works fine via browser, just unit tests are not
>> coming back right.
>>
>> --
>> - Paul Kenjora
>> - 602-214-7285 <(602)%20214-7285>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenG
>> YhwgG_GA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> Etienne Robillardtkadm30@yandex.comhttp://www.isotopesoftware.ca/
>>
>>
>
>
> --
> - Paul Kenjora
> - 602-214-7285 <(602)%20214-7285>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAEH8JE3W7kL8g64ZAWcOEJg1kDO%
> 2Bv9X6_%2BXHMeTSEjt8vxLsBw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEH8JE3W7kL8g64ZAWcOEJg1kDO%2Bv9X6_%2BXHMeTSEjt8vxLsBw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91ocsBS%2BePbLK8r51H1vHCpuhn%2BwUtnbWPaw2xKd%2B0bhmGA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible Bug Regarding model choices and form hidden input?

2017-10-28 Thread Paul Kenjora
*I use: *

Django version 1.7.0 - I know I know :)

Python 2.7.13

- Paul

On Sat, Oct 28, 2017 at 6:01 AM, Etienne Robillard 
wrote:

> Which Python and Django versions do you use?
>
> Etienne
>
> Le 2017-10-27 à 23:27, Paul Kenjora a écrit :
>
> Hi,
>
>   When setting HiddenInput on a form widget for an integer model field
> with choices, in tests I get 'X is not a valid choice' errors.  I'm
> guessing it's the hidden input returning a STRING and the model expecting
> an INT.
>
>   I have a model that has
>
>
> *class Banner(models.Model): *
>
> *  banner_x = models.PositiveIntegerField(blank=False, default=0,
> choices=enumerate(BANNER_XS))*
>
>
> And a form that has
>
> *class BannerForm(forms.ModelForm):*
>
> *  class Meta:*
>
> *model = Banner*
>
> *fields = ['banner_x']*
>
> *  def __init__(self, *args, **kwargs):*
>
> *kwargs['prefix'] = 'banner'*
>
> *super(BannerForm, self).__init__(*args, **kwargs)*
>
> *self.fields['banner_x'].widget = forms.HiddenInput()*
>
>
> In my unit tests I always get the error:
>
> *resp = self.client.post(**'/banner/, {*
>
> *  'banner-banner_x':0,*
>
>
> *}, follow=True) *
>
> *banner_xSelect a
> valid choice. 0 is not one of the available choices.*
>
>
> Anyone else seeing this?  Works fine via browser, just unit tests are not
> coming back right.
>
> --
> - Paul Kenjora
> - 602-214-7285 <(602)%20214-7285>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMj
> JUX9jXsr9tenGYhwgG_GA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Etienne Robillardtkadm30@yandex.comhttp://www.isotopesoftware.ca/
>
>


-- 
- Paul Kenjora
- 602-214-7285

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEH8JE3W7kL8g64ZAWcOEJg1kDO%2Bv9X6_%2BXHMeTSEjt8vxLsBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible Bug Regarding model choices and form hidden input?

2017-10-28 Thread Etienne Robillard

Which Python and Django versions do you use?

Etienne


Le 2017-10-27 à 23:27, Paul Kenjora a écrit :

Hi,

  When setting HiddenInput on a form widget for an integer model field 
with choices, in tests I get 'X is not a valid choice' errors.  I'm 
guessing it's the hidden input returning a STRING and the model 
expecting an INT.


  I have a model that has

*classBanner(models.Model):
*

*banner_x = models.PositiveIntegerField(blank=False, default=0, 
choices=enumerate(BANNER_XS))*


*
*

And a form that has

*classBannerForm(forms.ModelForm):*

*classMeta:*

*model = Banner*

*fields = ['banner_x']*

*def__init__(self, *args, **kwargs):*

*kwargs['prefix'] = 'banner'*

*super(BannerForm, self).__init__(*args, **kwargs)*

*self.fields['banner_x'].widget = forms.HiddenInput()*


In my unit tests I always get the error:

***resp = self.client.post(**'/banner/, {*

*'banner-banner_x':0,*

**

*}, follow=True)
*

*banner_xSelect a 
valid choice. 0 is not one of the available choices.*


*
*

Anyone else seeing this?  Works fine via browser, just unit tests are 
not coming back right.



--
- Paul Kenjora
- 602-214-7285
--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com>.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
Etienne Robillard
tkad...@yandex.com
http://www.isotopesoftware.ca/

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ffccbba-aee5-0cbf-2819-823d3bf9efd1%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Possible Bug Regarding model choices and form hidden input?

2017-10-27 Thread Paul Kenjora
Hi,

  When setting HiddenInput on a form widget for an integer model field with
choices, in tests I get 'X is not a valid choice' errors.  I'm guessing
it's the hidden input returning a STRING and the model expecting an INT.

  I have a model that has


*class Banner(models.Model):*

*  banner_x = models.PositiveIntegerField(blank=False, default=0,
choices=enumerate(BANNER_XS))*


And a form that has

*class BannerForm(forms.ModelForm):*

*  class Meta:*

*model = Banner*

*fields = ['banner_x']*

*  def __init__(self, *args, **kwargs):*

*kwargs['prefix'] = 'banner'*

*super(BannerForm, self).__init__(*args, **kwargs)*

*self.fields['banner_x'].widget = forms.HiddenInput()*


In my unit tests I always get the error:

*resp = self.client.post(**'/banner/, {*

*  'banner-banner_x':0,*


*}, follow=True)*

*banner_xSelect a valid
choice. 0 is not one of the available choices.*


Anyone else seeing this?  Works fine via browser, just unit tests are not
coming back right.

-- 
- Paul Kenjora
- 602-214-7285

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEH8JE3HuYObgFkpmVNnz39Gt7NMjJUX9jXsr9tenGYhwgG_GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


MultipleChoiceField records down choices as a list, but CharField converts them to a list?

2017-10-26 Thread Jack
I have a model field for choosing multiple options.  Here is the code for 
models and forms:

*models.py:*
CONDO_APARTMENT = 'Condo Apartment'
DETACHED_HOUSE = 'Detached House'
SEMI_DETACHED = 'Semi-detached'
TOWNHOUSE = 'Townhouse'

PROPERTY_TYPE = (
(CONDO_APARTMENT, 'Condo Apartment'),
(DETACHED_HOUSE, 'Detached House'),
(SEMI_DETACHED, 'Semi-detached'),
(TOWNHOUSE, 'Townhouse'),
)

property_type = models.CharField(max_length=50, help_text="You can 
select more than 1 option")


*forms.py:*
property_type = forms.MultipleChoiceField(widget=forms.SelectMultiple, 
choices=BuyerListing.PROPERTY_TYPE)


Let's assume the selected choices were 'Condo Apartment' and 
'Semi-detached'.  The value stored on my database is this - ['Condo 
Apartment', 'Semi-detached']

Now this is in a list format, which makes sense, but it seems to have been 
converted to a string.  When I try to call on property_type in a .html 
document...

{% for property in model.property_type %}
{{ property }}
{% endfor %}

The result is displayed in singular characters, like this:

[
'
C
o
n
d
o
 
a
p
.. and so on.  Instead I want the result to be the values in the list, like 
this:

Condo apartment
Semi-detached

How do I do this?  I tried experimenting with different model field types 
but CharField seems like the only appropriate one for MultipleChoiceField.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/06ff88b7-4ec4-4ddc-a4da-af8e25e3c516%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Building a search form with 4 required choices, which will be inserted as arguments in an URL [warning: long question]

2017-10-23 Thread Jack Zhang
This is a semi-long question.  Please let me know wherever I make a mistake.

I'm building a search form with 4 required choices, 1 of the choices is a 
CharField with a max_length of 3.  The other 3 choices are ChoiceField's.  
Here is a picture of what the search form looks like:

<https://lh3.googleusercontent.com/-8GREjIuYfMc/We4LXpdGMtI/CeI/lF08A9M1zj4gL3saaVvKY9rWZ4APYU4EACLcBGAs/s1600/Capture.PNG>

I've read through the Django docs and other things on the Internet but I'm 
still very unclear about how to approach this.

1. First I believe I need to create 4 args or kwargs in the url for each of 
the choices.  If I use args, it would look something like...

url(r'^search?(\w+{3})&(\w+{2})&(\w+{1-2})&(\w+{1-2})', function/class 
view, name='search')

2. Next, I need to pass the user's input in the html page into the url 
args.  I have a form set up to get the user's input.  But how would I write 
this on the HTML page?  Do I simply make a url tag like {% url 'search' 
args1, args2, args3, args4 %}?

3. Then I need to create the views function.  My first question is, should 
I use a function-based view or the generic class-based ListView?  The 
result of the search will be a list of items, so ListView is a good 
template to use, but I don't know how having 4 args would affect using 
ListView.  My second question is, what is the most effective way of making 
this search?  I need to check if any records in the database matches the 
user's search, so would I do something like 'For record in database' to 
check over every record in the database?

If I used a function view, would it look something like:

def search(request, args1, args2, args3, args4):
 for record in database:
  if args matches record:
   display record

Thank you for reading through the question

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/01912c3f-f10b-4134-8731-908b6585d6c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: dynamic choices based on another field input.

2017-10-22 Thread Derek
See:

http://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#filtering-results-based-on-the-value-of-other-fields-in-the-form


On Friday, 20 October 2017 13:04:41 UTC+2, rajeev yadla wrote:
>
> hi have a form which have two fields. one field has a foreignkey from 
> model A(in image) base field. and another field is a drop down box where 
> the choices should be dynamic based on first field selection. the choices 
> should all the values of field Os from second model B associated with the 
> Base key value i have given in first field. 
> example from image. 
> field 1= 10
> field 2= (A,C) as these two values are associted with 10 in model B.
>
>
> <https://lh3.googleusercontent.com/-G4zAE_Sz820/WemSa21SxfI/AqM/E2HzoElN4jsGhaZDpfnANntIzProBdGvACLcBGAs/s1600/IMG_20171020_111902071.jpg>
>
> can someone help me here.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3363444-83d8-46e1-aaf1-7cf31c657e94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


dynamic choices based on another field input.

2017-10-20 Thread rajeev yadla


hi have a form which have two fields. one field has a foreignkey from model 
A(in image) base field. and another field is a drop down box where the 
choices should be dynamic based on first field selection. the choices 
should all the values of field Os from second model B associated with the 
Base key value i have given in first field. 
example from image. 
field 1= 10
field 2= (A,C) as these two values are associted with 10 in model B.

<https://lh3.googleusercontent.com/-G4zAE_Sz820/WemSa21SxfI/AqM/E2HzoElN4jsGhaZDpfnANntIzProBdGvACLcBGAs/s1600/IMG_20171020_111902071.jpg>

can someone help me here.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ff8c070-325a-4cf7-abe1-6fb59f985b40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Choices in DecimalField - django 1.8.

2017-09-19 Thread Gordon Wrigley
In case anyone else ends up here, I've found that it's very sensitive to 
how you specify the Decimal, so in my example Decimal('20.00') worked but 
Decimal('20') and Decimal(20) did not.

On Monday, April 20, 2015 at 6:44:30 PM UTC+1, eltonplima wrote:
>
> In the model below, using the Django admin, no matter what value I choose, 
> it always displays the default value. But writes the correct value in the 
>  database. Am I doing something wrong or is this a bug?
>
> TENSAO_220 = Decimal(220)
> TENSAO_110 = Decimal(110)
> TENSOES = ((TENSAO_220, '220 volts'),
>(TENSAO_110, '110 volts'))
>
> class Equipamento(models.Model):
> nome = models.CharField(max_length=128)
>   tensao = models.DecimalField(max_digits=8,
>decimal_places=3,
>choices=TENSOES,
>default=TENSAO_220)
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/26c4211e-fabe-47d7-b930-1da31fedeb01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


choices choice utility

2017-05-05 Thread Mike Dewhirst
Because I use many of the same constants in different apps in my project 
I keep most of them including almost all choices in a single __init__.py 
file and import them wherever required.


Here is a tiny utility I use all the time ... whenever 
get__display() is inappropriate.



def choose(choices, choice):
for pair in choices:
if pair[0] == choice:
return pair[1]
for section in choices:
for pair in section[1]:
if pair[0] == choice:
return pair[1]


Hope someone finds it useful. Also, I'm sure it can be made much more 
pythonic. It is Friday after all :)


Cheers

Mike




--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fe15d311-84bf-99fc-1511-767c83572e3b%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Limiting choices in a lookup by exclusion

2017-02-01 Thread Melvyn Sopacua
And there's 2 other options to consider:

 *  The ne lookup is actually the first example in the documentation for 
custom 
lookups[1]. So you get its implementation for free and can consider adding it.
 *  You can extend Field to add exclude_choices() which sets 
limit_choices_to to the 
negation of the argument as below - so wrap it with ~Q().
All depending on how isolated your case is in the project/app.

On Tuesday 31 January 2017 23:48:28 C. Kirby wrote:
> django doesn't have an ne operator in the orm. You want to use a
> negated Q object for your limit_choices_to. try:
> 
> from django.db.models import Q
> 
> phone = models.ManyToManyField(Phone, limit_choices_to = ~Q(type_id =
> 'C'))
> On Wednesday, February 1, 2017 at 6:17:52 AM UTC+2, Gordon Burgess wrote:
> > I have this code, and with Django 1.10 it works as expected:
> > 
> > class Location(models.Model):
> > name = models.CharField(max_length = 32, unique = True)
> > street = models.CharField(max_length = 32)
> > detail = models.CharField(max_length = 32, blank = True, null =
> > True)
> > city = models.CharField(max_length = 32)
> > state = USStateField()
> > zip = USZipCodeField()
> > phone = models.ManyToManyField(Phone, limit_choices_to =
> > 
> > {'type_id':'H'})
> > 
> > but what I'd like to do is restrict the choices of phone numbers for
> > Locations to those that aren't 'C' (cell phones) - I've found some
> > hints,> 
> > but they're all for older versions of Django - it seems like:
> > phone = models.ManyToManyField(Phone, limit_choices_to =
> > 
> > {'type_id__ne':'C'})
> > 
> > ought to work - but this provokes a TypeError:
> > 
> > Related Field got invalid lookup: ne
> > 
> > Thanks!

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/1.10/howto/custom-lookups/

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2680435.EONmJTctep%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Limiting choices in a lookup by exclusion

2017-01-31 Thread C. Kirby
django doesn't have an ne operator in the orm. You want to use a negated Q 
object for your limit_choices_to. try:

from django.db.models import Q

phone = models.ManyToManyField(Phone, limit_choices_to = ~Q(type_id = 'C'))

On Wednesday, February 1, 2017 at 6:17:52 AM UTC+2, Gordon Burgess wrote:
>
>
> I have this code, and with Django 1.10 it works as expected:
>
> class Location(models.Model):
> name = models.CharField(max_length = 32, unique = True)
> street = models.CharField(max_length = 32)
> detail = models.CharField(max_length = 32, blank = True, null = True)
> city = models.CharField(max_length = 32)
> state = USStateField()
> zip = USZipCodeField()
> phone = models.ManyToManyField(Phone, limit_choices_to = 
> {'type_id':'H'})
>
> but what I'd like to do is restrict the choices of phone numbers for 
> Locations to those that aren't 'C' (cell phones) - I've found some hints, 
> but they're all for older versions of Django - it seems like:
>
> phone = models.ManyToManyField(Phone, limit_choices_to = 
> {'type_id__ne':'C'})
>
> ought to work - but this provokes a TypeError:
>
> Related Field got invalid lookup: ne
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37b94253-fd0e-479f-8c0d-ffe262b1dcd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Limiting choices in a lookup by exclusion

2017-01-31 Thread Gordon R. Burgess

I have this code, and with Django 1.10 it works as expected:

class Location(models.Model):
name = models.CharField(max_length = 32, unique = True)
street = models.CharField(max_length = 32)
detail = models.CharField(max_length = 32, blank = True, null = True)
city = models.CharField(max_length = 32)
state = USStateField()
zip = USZipCodeField()
phone = models.ManyToManyField(Phone, limit_choices_to = {'type_id':'H'})

but what I'd like to do is restrict the choices of phone numbers for Locations
to those that aren't 'C' (cell phones) - I've found some hints, but they're all
for older versions of Django - it seems like:

    phone = models.ManyToManyField(Phone, limit_choices_to =
{'type_id__ne':'C'})

ought to work - but this provokes a TypeError:

Related Field got invalid lookup: ne

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1485922364.17463.7.camel%40parasamgate.com.
For more options, visit https://groups.google.com/d/optout.


How to make properly choices based on two models?

2016-09-24 Thread Anton Ponomarenko
Hello.

I want to let users to choose their countries. I have 2 models = *Countries* 
with some figures and *CountriesTranslations*. I am trying to make tuple 
with *country* (because user has FK to this model) and its *translation*. 
In front-end I see dropdown list of countries, but when I try to save the 
form, I see error: *Exception Value: Cannot assign "'AF'": 
"UserProfile.country" must be a "Countries" instance.* Error happens at the 
line *if user_profile_form.is_valid():*

# admindivisions.models
class Countries(models.Model):
osm_id = models.IntegerField(db_index=True, null=True)
status = models.IntegerField()
population = models.IntegerField(null=True)

iso3166_1 = models.CharField(max_length=2, blank=True)
iso3166_1_a2 = models.CharField(max_length=2, blank=True)
iso3166_1_a3 = models.CharField(max_length=3, blank=True)

class Meta:
db_table = 'admindivisions_countries'
verbose_name = 'Country'
verbose_name_plural = 'Countries'


class CountriesTranslations(models.Model):
common_name = models.CharField(max_length=81, blank=True, db_index=True)
formal_name = models.CharField(max_length=100, blank=True)

country = models.ForeignKey(Countries, on_delete=models.CASCADE, 
verbose_name='Details of Country')
lang_group = models.ForeignKey(LanguagesGroups, on_delete=models.CASCADE
, verbose_name='Language of Country',
   null=True)

class Meta:
db_table = 'admindivisions_countries_translations'
verbose_name = 'Country Translation'
verbose_name_plural = 'Countries Translations'


# profiles.forms
class UserProfileForm(forms.ModelForm):

# PREPARE CHOICES
country_choices = ()
lang_group = Languages.objects.get(iso_code='en').group
for country in Countries.objects.filter(status=1):
eng_name = country.countriestranslations_set.filter(lang_group=
lang_group).first()
if eng_name:
country_choices += ((country, eng_name.common_name),)
country_choices = sorted(country_choices, key=lambda tup: tup[1])


country = forms.ChoiceField(choices=country_choices, required=False)

class Meta:
model = UserProfile()
fields = ('email', 'email_privacy',
  'profile_url',
  'first_name', 'last_name',
  'country',)


# profiles.views
def profile_settings(request):
if request.method == 'POST':
user_profile_form = UserProfileForm(request.POST, instance=request.
user)

if user_profile_form.is_valid():
user_profile_form.save()
messages.success(request, _('Your profile was successfully 
updated!'))

return redirect('settings')

else:
messages.error(request, _('Please correct the error below.'))

else:
user_profile_form = UserProfileForm(instance=request.user)

return render(request, 'profiles/profiles_settings.html', {
'user_profile_form': user_profile_form,
})

As I understand, *country* from *((country, eng_name.common_name),)* is 
converted to *str*. What is the right way to keep country instance in the 
form? or if I am doing it in the wrong way, what way is correct?

As a possible solution is to use *ModelChoiceField* with overriding 
*label_from_instance* as shown below:
class CountriesChoiceField(forms.ModelChoiceField):
def __init__(self, user_lang='en', *args, **kwargs):
super(CountriesChoiceField, self).__init__(*args, **kwargs)
self.user_lang = user_lang

def label_from_instance(self, obj):
return obj.countriestranslations_set.get(lang_group=self.user_lang)


class UserProfileForm(forms.ModelForm):
user_lang = user_lang_here
country = CountriesChoiceField(
queryset=Countries.objects.filter(
status=1, iso3166_1__isnull=False,
countriestranslations__lang_group=user_lang).order_by(
'countriestranslations__common_name'),
widget=forms.Select(), user_lang=user_lang)

class Meta:
model = UserProfile()
fields = ('email', 'email_privacy',
  'profile_url',
  'first_name', 'last_name',
  'country',)

but in this case there are too much queries because of the 
*label_from_instance* and page loads too slowly.
Would appreciate any advice how to solve this task.
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b2b0e010-f549-4225-93a3-ee42249a6120%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: choices field language

2016-06-21 Thread Luis Zárate
Use in the first line

#- coding: utf-8
from __future__ import unicode_literals

And put in models



from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible
class MyClass(object):
   def __str__(self):
   return "Instance of my class"

See more in

https://docs.djangoproject.com/en/1.9/topics/python3/



El martes, 21 de junio de 2016, ludovic coues  escribió:
> Python 3 have a better support of international alphabet.
>
> 2016-06-20 23:44 GMT+02:00 Xristos Xristoou :
>> hello i want to use choices in my field but not work if i write in my
>> language(greek) only work in the england language.
>> if i writing choices in my language show me error message in the admin
mode
>> (this choose is not valid),any idea how to fix that ?i have python 2.7
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>>
https://groups.google.com/d/msgid/django-users/5bfdb5b9-e286-40e1-aa8b-2a0e68878204%40googlegroups.com
.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAEuG%2BTaq-wqgpk1k2B%2BiGWesPdo32OvRhFGAEHu%2BwC7p25%2BmHQ%40mail.gmail.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%2B5VyNZF6SjWdN4y5Q9zs8rWisy4%3D6KOj2G3NngiomsFn1dow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: choices field language

2016-06-21 Thread ludovic coues
Python 3 have a better support of international alphabet.

2016-06-20 23:44 GMT+02:00 Xristos Xristoou :
> hello i want to use choices in my field but not work if i write in my
> language(greek) only work in the england language.
> if i writing choices in my language show me error message in the admin mode
> (this choose is not valid),any idea how to fix that ?i have python 2.7
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5bfdb5b9-e286-40e1-aa8b-2a0e68878204%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTaq-wqgpk1k2B%2BiGWesPdo32OvRhFGAEHu%2BwC7p25%2BmHQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


choices field language

2016-06-20 Thread Xristos Xristoou
hello i want to use choices in my field but not work if i write in my 
language(greek) only work in the england language.
if i writing choices in my language show me error message in the admin mode 
(this choose is not valid),any idea how to fix that ?i have python 2.7

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5bfdb5b9-e286-40e1-aa8b-2a0e68878204%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FieldError: Cannot resolve keyword u'domain' into field. Choices are: children, content, date_create, date_update, domain__associations, id, level, lft, name, parent, parent_id, rght, tree_id, use

2016-05-17 Thread Michal Petrucha
On Tue, May 17, 2016 at 05:58:51AM -0700, François GUÉRIN wrote:
> Thanks very very very much !

You're welcome. (-:

On Tue, May 17, 2016 at 05:56:23AM -0700, François GUÉRIN wrote:
> Argh !! It works ! We could use double underscores in relation names, 
> before, no ?

I don't think so – if it ever worked, then it was only if you
restricted yourself to a very limited subset of the relationship API,
and only by accident. Double underscores are, just like field names
(or related_names) ending with underscores, impossible to support,
because of the double underscore separator in cross-relationship
lookups.

Arguably, there should be a check that would flag this as an error.
I'll try to create a test case and patch for this later today...

Cheers,

Michal

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20160517130949.GJ24966%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: FieldError: Cannot resolve keyword u'domain' into field. Choices are: children, content, date_create, date_update, domain__associations, id, level, lft, name, parent, parent_id, rght, tree_id, use

2016-05-17 Thread François GUÉRIN
Thanks very very very much !

Le mardi 17 mai 2016 14:51:05 UTC+2, Michal Petrucha a écrit :
>
> On Tue, May 17, 2016 at 05:44:24AM -0700, François GUÉRIN wrote: 
> > Hi all, 
> > 
> > I'm a django application dev for a few years, so I'm pretty familiar 
> with 
> > it. I have a problem with a new django 1.9.6 application. I'm writing a 
> > directory app, with a main model named "Association", which have 4 m2m 
> > related fields : 
> > 
> > 
> > class Association(models.Model): 
> > # ... other fields ... 
> > 
> > #: Activity domains. 
> > #: note:: An association **MUST** have at least 1 activity, it can 
> have some more. 
> > domains = models.ManyToManyField(Domain, verbose_name=_('domains'), 
> related_name='domain__associations') 
> > 
> > #: Targeted age groups 
> > target_groups = models.ManyToManyField(TargetGroup, 
> verbose_name=_('target groups'), 
> >blank=True, 
> related_name='target_group__associations') 
> > 
> > #: Locations where the activities of the association can take places 
> > locations = models.ManyToManyField(Location, 
> verbose_name=_('locations'), 
> >blank=True, 
> related_name='location__associations') 
> > 
> > #: Affiliations 
> > affiliations = models.ManyToManyField(Affiliation, 
> verbose_name=_('affiliations'), blank=True, 
> >   
> related_name='affiliation__associations') 
> > 
> > 
> > When I try to access to related data; I always have (aka, for each 
> related 
> > field) a Field Error exception, has given in title. The keyword allways 
> > asks for the field name in the relation table, and the field list 
> displayed 
> > are from the target table of the relation. Trlated tables are pretty 
> simple 
> > (name, description), but domain is a mptt table. 
> > 
> > With factory_boy, I can create new `Association` items and insert new 
> > relations to my related items, but I can't display them. 
> > 
> > I'm stuck with this problem for a few days, that why I ask... I really 
> > don't see what I didn't do... or understand ! 
> > 
> > Thanks for your help ! 
>
> Hi François, 
>
> At a quick glance, it seems the error is that you put double 
> underscores into related_names. That cannot work, because 
> related_names should follow the same restrictions as regular field 
> names, and field names cannot contain double underscores, since Django 
> uses those to separate fields when traversing relations. 
>
> Cheers, 
>
> Michal 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f65016e9-cab6-4b6b-82e1-f9d2c600bf59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   5   6   7   8   9   >