Re: Inlineformset without foreign key possible?
Thank you for pointing me in the right direction =) looks like that class is more generic. On Tuesday, June 5, 2018 at 9:08:35 PM UTC, Matthew Pava wrote: > > I’m not able to wrap my head around your specific application, but if you > don’t want to use a ForeignKey on a formset, don’t use an InlineFormset. > > Just use a regular BaseFormset. > > https://docs.djangoproject.com/en/2.0/topics/forms/formsets/ > -- 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/50ce8098-0a00-439a-bdbf-57f340117f20%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django formset for models without foreign key
I'm trying to use formset to create connections between my Neo4j nodes. These models have been constructed using the django-neomodel package. They aren't related using foreign keys, but since this *isn't* an inline formset that shouldn't matter, right? *models.py* class Person(DjangoNode): uid = UniqueIdProperty() name = StringProperty(max_length=50) created_at = DateTimeProperty(default=datetime.now) friends = RelationshipTo('Friend', 'FRIENDED', model=FriendRel) # DjangoNode class must have a Meta class and documentation specifies 'django_node' class Meta: app_label = 'django_node' class FriendRel(DjangoRel): created_at = DateTimeProperty(default=datetime.now) class Meta: app_label = 'django_rel' *forms.py* class PersonForm(forms.ModelForm): class Meta: model = Person # don't need fields for automatically assigned keys like `uid` and `created_at` fields = ['name'] class FriendRelForm(forms.ModelForm): class Meta: model = FriendRel exclude = () #"creating ModelForm without either 'fields' || 'exclude' attribute is prohibited" FriendRelFormSet = formset_factory(FriendRelForm, extra=1) *form.html* {% csrf_token %} {{ form.as_p }} {{ friends.management_form }} {% for form in friends.forms %} {% if forloop.first %} {% for field in form.visible_fields %} {{ field.label|capfirst }} {% endfor %} {% endif %} {% for field in form.visible_fields %} {% if forloop.first %} {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} {% endif %} {{ field.errors.as_ul }} {{ field }} {% endfor %} {% endfor %} I'm expecting a "friend" formset to appear in the rendered form, but am not quite sure how to get it there. If I add the following I get an error: class FriendRelForm(forms.ModelForm): class Meta: model = FriendRel exclude = () fields = ['friends'] ERROR*** django.core.exceptions.FieldError: Unknown field(s) (friends) specified for FriendRel* -- 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/3e387c8a-522b-4278-8784-aff15f0d9602%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django formset for models without foreign key
I'm trying to use formset to create connections between my Neo4j nodes. These models have been constructed using the django-neomodel package. They aren't related using foreign keys, but since this *isn't* an inline formset that shouldn't matter, right? *models.py* class Person(DjangoNode): uid = UniqueIdProperty() name = StringProperty(max_length=50) created_at = DateTimeProperty(default=datetime.now) friends = RelationshipTo('Friend', 'FRIENDED', model=FriendRel) # DjangoNode class must have a Meta class and documentation specifies 'django_node' class Meta: app_label = 'django_node' class FriendRel(DjangoRel): created_at = DateTimeProperty(default=datetime.now) class Meta: app_label = 'django_rel' *forms.py* class PersonForm(forms.ModelForm): class Meta: model = Person # don't need fields for automatically assigned keys like `uid` and `created_at` fields = ['name'] class FriendRelForm(forms.ModelForm): class Meta: model = FriendRel exclude = () #"creating ModelForm without either 'fields' || 'exclude' attribute is prohibited" FriendRelFormSet = formset_factory(FriendRelForm, extra=1) *form.html* {% csrf_token %} {{ form.as_p }} {{ friends.management_form }} {% for form in friends.forms %} {% if forloop.first %} {% for field in form.visible_fields %} {{ field.label|capfirst }} {% endfor %} {% endif %} {% for field in form.visible_fields %} {% if forloop.first %} {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} {% endif %} {{ field.errors.as_ul }} {{ field }} {% endfor %} {% endfor %} I'm expecting a "friend" formset to appear in the rendered form, but am not quite sure how to get it there. If I add the following I get an error: class FriendRelForm(forms.ModelForm): class Meta: model = FriendRel exclude = () fields = ['friends'] ERROR*** django.core.exceptions.FieldError: Unknown field(s) (friends) specified for FriendRel* -- 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/a3094b31-9ce9-4760-b2a2-56dce3b3c3f4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Pass value from view to non-model form
When I call my form in my view, I am trying to pass MY_VALUE to the form as an argument. I am doing this because I want to get my validation out of my views and into my forms. *views.py* OTHER_VALUE = "the query that i run" if request.method=='POST': form = MY_FORM(request.POST, OTHER_VALUE) *forms.py* class MY_FORM(forms.Form): real_value = forms.CharField() def clean_real_value(self): if OTHER_VALUE ... *This throws the error:* __init__() got an unexpected keyword argument 'OTHER_VALUE' = I've tried setting the init with kwargs class MY_FORM(forms.Form): real_value = forms.CharField() def __init__(self, *args, **kwargs): OTHER_VALUE = kwargs.pop('OTHER_VALUE') super(MY_FORM, self).__init__(*args, **kwargs) error: Exception Value: 'employee' Exception Location: /Users/macbook/Desktop/OrgDB/orgchart/forms.py in __init__, line 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/61a17825-0a19-4573-8893-49e1b715d045%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Pass value from view to non-model form
It seems to like that! `(arg1, OTHER_VAL=OTHER_VAL) Now I'm trying to access that other_value: def __init__(self, *args, **kwargs): OTHER_VAL = kwargs.get('OTHER_VAL') #tried these: #kwargs['OTHER_VAL'] #kwargs.pop('OTHER_VAL') super(MY_FORM, self).__init__(*args, **kwargs) Keep on getting errors like: `KeyError: 'OTHER_VAL'` # or __init__() got an unexpected keyword argument 'OTHER_VAL' On Saturday, June 23, 2018 at 9:56:15 AM UTC-4, Tomasz Knapik wrote: > > You get that error because you use kwargs.pop (presumably that's why) and > you pass OTHER_VALUE as a positional argument. > > E.g. > > MY_FORM(request.POST, OTHER_VALUE=OTHER_VALUE) > > > would pass it as a keyword argument and then you can > use kwargs.pop('OTHER_VALUE') in the form's init. > > On Fri, 2018-06-22 at 18:37 -0700, HashRocketSyntax wrote: > > When I call my form in my view, I am trying to pass MY_VALUE to the form > as an argument. > > I am doing this because I want to get my validation out of my views and > into my forms. > > *views.py* > OTHER_VALUE = "the query that i run" > if request.method=='POST': > form = MY_FORM(request.POST, OTHER_VALUE) > > *forms.py* > class MY_FORM(forms.Form): > > real_value = forms.CharField() > def clean_real_value(self): > if OTHER_VALUE ... > > > *This throws the error:* > __init__() got an unexpected keyword argument 'OTHER_VALUE' > > > = > > I've tried setting the init with kwargs > class MY_FORM(forms.Form): > real_value = forms.CharField() > > def __init__(self, *args, **kwargs): > OTHER_VALUE = kwargs.pop('OTHER_VALUE') > super(MY_FORM, self).__init__(*args, **kwargs) > > > error: > Exception Value: 'employee' > Exception Location: /Users/macbook/Desktop/OrgDB/orgchart/forms.py in > __init__, line 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...@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/61a17825-0a19-4573-8893-49e1b715d045%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/61a17825-0a19-4573-8893-49e1b715d045%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/cec9f435-b36b-46df-a384-e0f81d4deb33%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Pass value from view to non-model form
Looks like I was missing an `initial` inside init... 0_o https://stackoverflow.com/questions/1993014/passing-kwargs-to-django-form On Friday, June 22, 2018 at 9:37:26 PM UTC-4, HashRocketSyntax wrote: > > When I call my form in my view, I am trying to pass MY_VALUE to the form > as an argument. > > I am doing this because I want to get my validation out of my views and > into my forms. > > *views.py* > OTHER_VALUE = "the query that i run" > if request.method=='POST': > form = MY_FORM(request.POST, OTHER_VALUE) > > *forms.py* > class MY_FORM(forms.Form): > > real_value = forms.CharField() > def clean_real_value(self): > if OTHER_VALUE ... > > > *This throws the error:* > __init__() got an unexpected keyword argument 'OTHER_VALUE' > > > = > > I've tried setting the init with kwargs > class MY_FORM(forms.Form): > real_value = forms.CharField() > > def __init__(self, *args, **kwargs): > OTHER_VALUE = kwargs.pop('OTHER_VALUE') > super(MY_FORM, self).__init__(*args, **kwargs) > > > error: > Exception Value: 'employee' > Exception Location: /Users/macbook/Desktop/OrgDB/orgchart/forms.py in > __init__, line 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/43fa9a79-892a-451d-86e1-c945eb53c85e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Pass value from view to non-model form
SOLVED. https://stackoverflow.com/questions/50997267/django-pass-value-from-view-to-non-model-form/51002442#51002442 thank you for pointing me in the right direction On Friday, June 22, 2018 at 9:37:26 PM UTC-4, HashRocketSyntax wrote: > > When I call my form in my view, I am trying to pass MY_VALUE to the form > as an argument. > > I am doing this because I want to get my validation out of my views and > into my forms. > > *views.py* > OTHER_VALUE = "the query that i run" > if request.method=='POST': > form = MY_FORM(request.POST, OTHER_VALUE) > > *forms.py* > class MY_FORM(forms.Form): > > real_value = forms.CharField() > def clean_real_value(self): > if OTHER_VALUE ... > > > *This throws the error:* > __init__() got an unexpected keyword argument 'OTHER_VALUE' > > > = > > I've tried setting the init with kwargs > class MY_FORM(forms.Form): > real_value = forms.CharField() > > def __init__(self, *args, **kwargs): > OTHER_VALUE = kwargs.pop('OTHER_VALUE') > super(MY_FORM, self).__init__(*args, **kwargs) > > > error: > Exception Value: 'employee' > Exception Location: /Users/macbook/Desktop/OrgDB/orgchart/forms.py in > __init__, line 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/d60af4c2-de33-4818-913f-6bbc68e39f26%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Clean ValidationError not showing when form.is_valid() called
I'm trying to show my ValidationError from clean_MY_VALUE in the template. *template* {% csrf_token %} {{form.as_p}} Submit {{ form.errors }} {{ form.non_field_errors }} *views.py* def MY_VIEW_CLASS(request, MY_ARG): MY_ARG = "query to check for silly conditions" if request.method=='POST': form = MY_FORM(request.POST) if form.is_valid(): MY_VALUE = form.cleaned_data['MY_VALUE'] # do more stuff *forms.py* class MY_FORM(forms.Form): MY_VALUE = forms.CharField( required = True, max_length = 70, ) def __init__(self, *args, **kwargs): self.MY_ARG = kwargs.pop('MY_ARG', None) super(MY_FORM, self).__init__(*args, **kwargs) def clean_MY_VALUE(self): data = self.cleaned_data['MY_VALUE'] MY_ARG = self.MY_ARG if MY_VALUE and MY_ARG == True: raise ValidationError("this is the error message.") if any(self.errors): return self.errors # return the cleaned data return data *Debug* What's weird is that when I debug, I cannot see the ValidationError I just created in errors. (Pdb) raise forms.ValidationError("That is causing an error.")*** django.core.exceptions.ValidationError: ['That is causing an error.'] (Pdb) self.errors{} -- 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/e9fbe8a8-35f3-4f30-9575-919a91bb9579%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django how to go about using npm modules with static/ templates
I have recently added *npm* to my project in order to keep better track of my js dependencies. Previously I have just been git cloning to my static/vendor folder. I've also added *gulp* , but have only got it doing hello world things right now. It seems simple enough - it can watch files, minify assets, compile Sass. Eventually I will probably switch to *Webpack*, but gulp is simple and working for now. I don't want to use *django-compressor* or *django-pipeline*. -- So let's say I run npm install vis to pull in visjs. It gets added to node_modulesand a record is added to package.json dependencies. *A)* Do I reference vis/dist right where it is in node_mods in my template scripts? # right now it's
Are forms supposed to submit empty strings for blank fields?
I'm running into problems downstream with empty strings. Are django forms supposed to submit empty strings for form fields that are not filled 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/96856b6f-9733-4460-92c3-293888337072%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Are forms supposed to submit empty strings for blank fields?
Shouldn't they be None? -- 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/3be26bc0-20f6-4f58-94c2-c2be6ab3480f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.