Key Error in form.cleaned_data

2019-08-08 Thread Mei B
I'm using a formset, and i'm trying to iterate through all the cleaned 
data except I keep getting a Keyerror no matter what field I try..

for form in formset:
   data = form.cleaned_data
   name = data["name"]

--->  KeyError: "name"

class VariableForm(forms.Form):
name = forms.CharField()
default = forms.CharField(required=False)

Formset = formset_factory(
VariableForm,
can_delete=True,
extra=1,
)

What is wrong with my code?

I can even print(data) and it outputs:
 {'DELETE': False, 'name': 'PATH', 'default': '/opt/tests'}

I can even do, for key, value in data.items(): and output
delete false
   name PATH


-- 
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/a90c04fa-6e1b-4a3d-a813-2661cc6df725%40googlegroups.com.


Re: How to customize AdminWidget FilteredSelectMultiple?

2019-07-23 Thread Mei B
I figured out how to customize what I want by editing SelectFilter2.js, 
located in /admin/js/SelectFilter2.js
My question now is, how do I get django to look at this new 
SelectFilter2.js instead of the original?
I thought I would pop it in my_app/static/admin/js/ but that doesn't seem 
to be working.



On Monday, July 22, 2019 at 5:21:08 PM UTC-7, Mei B wrote:
>
> I'm trying to use the admin widget FilteredSelectMultiple, I can get it to 
> render on my page, but I want to customize it a bit more.
>
> I want to change the labels from available/chosen, change the size, and 
> reorder the boxes (have chosen be on the left) How do I go about doing 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/703f10d8-6e0e-4901-a3d9-04e591fdcd10%40googlegroups.com.


How to customize AdminWidget FilteredSelectMultiple?

2019-07-22 Thread Mei B
I'm trying to use the admin widget FilteredSelectMultiple, I can get it to 
render on my page, but I want to customize it a bit more.

I want to change the labels from available/chosen, change the size, and 
reorder the boxes (have chosen be on the left) How do I go about doing 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/9ea91cc1-f1b7-44ea-9a40-8b1b5257cdf3%40googlegroups.com.


Re: formset has_changed always return true.

2019-06-11 Thread Mei B
Yes I am already instantiated the form and check has_changed after.

On Tuesday, June 11, 2019 at 8:59:46 AM UTC-7, Gil Obradors wrote:
>
> Hi!
> Have you instanced first de form?
> Maybe this code from djano help you
>
> from django.http import HttpResponseRedirectfrom django.shortcuts import 
> render
> from .forms import NameForm
> def get_name(request):
> # if this is a POST request we need to process the form data
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = NameForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> # process the data in form.cleaned_data as required
> # ...
> # redirect to a new URL:
> return HttpResponseRedirect('/thanks/')
>
> # if a GET (or any other method) we'll create a blank form
> else:
> form = NameForm()
>
> return render(request, 'name.html', {'form': form})
>
>
> Maybe you can check has_changed() after  form= 
> Nameofyourforminformspy(request.POST) ?
> good luck
>
>
> https://docs.djangoproject.com/en/2.2/topics/forms/
> https://docs.djangoproject.com/en/2.2/topics/forms/formsets/
>
> Missatge de Mei B > del dia dt., 11 de 
> juny 2019 a les 4:33:
>
>>if request.method == "POST":
>> formset = forms.Formset(data=request.POST, initial=initial)
>> if not formset.has_changed(): #has_changed always returns 
>> true! 
>> msg = "No changes detected."
>>
>> if formset.has_changed() and formset.is_valid()
>> do stuff...
>> else:
>> formset = forms.Formset(initial=initial)
>> formset_get = formset
>>
>> What am i doing wrong?
>>
>> -- 
>> 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 post to this group, send email to django...@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/23af35da-2f85-4512-9842-6b6811f3988b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/23af35da-2f85-4512-9842-6b6811f3988b%40googlegroups.com?utm_medium=email_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/6c34158d-cbd0-4839-b35b-edbfea16a535%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


formset has_changed always return true.

2019-06-10 Thread Mei B
   if request.method == "POST":
formset = forms.Formset(data=request.POST, initial=initial)
if not formset.has_changed(): #has_changed always returns true! 
msg = "No changes detected."

if formset.has_changed() and formset.is_valid()
do stuff...
else:
formset = forms.Formset(initial=initial)
formset_get = formset

What am i doing wrong?

-- 
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/23af35da-2f85-4512-9842-6b6811f3988b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Order_by ManyToMany relation?

2019-06-05 Thread Mei B
I have a form for a model that contains a ManyToMany relationship to model 
B.
By default, manytomany relationship on forms are SelectMuliple and orders 
them by alphabetical.
How can I order by if they already have a relation?

In my forms.py

class FormA(forms.ModelForm):
class Meta:
model = models.A

def __init___(self, *args, **kwargs):
  super(FormA, self).__init__(*args, **kwargs)
  self.fields["b"].queryset = models.B.objects.order_by(???)

If model B has objects: "a, a1, a2, b, b2"
And model A has a many to many relationship with B's "a, a2, b2"
How can I order the objects so it'll show "a, a2, b2, a1, b" on the form?

-- 
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/e48671f7-9f21-49c7-b664-0545161d0fa7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Legacy DB: ID is null when .save or .create

2019-05-17 Thread Mei B
I'm using a legacy DB with postgres. In one of my models:

class case(models.Model):
 id = models.AutoField(primary_key=True)
 case_id = models.ForeignKey(.)
 user_id = models.ForeignKey(...)

When I'm saving or creating a new case object, I always get "null value in 
column 'id' violates not-null"

How do I get this to auto-increment?

-- 
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/5d621db9-39e8-44c8-92e2-80fdabc760af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.