Re: how can I work with multi model forms

2018-12-27 Thread Danny Blaker
https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#inline-formsets

https://github.com/elo80ka/django-dynamic-formset/blob/master/docs/usage.rst
https://github.com/elo80ka/django-dynamic-formset/blob/master/INSTALL.rst

clone the above, then check the examples




On Wednesday, 26 December 2018 23:29:11 UTC+11, Tessnim Zrayga wrote:
>
> Hello everyone,
> I have this design: there's a firm, a firm can have multiple nodes. Each 
> node can have many scheduled actions. What I'm trying to do is to create a 
> template containing all informations about a firm and be able to create 
> multiple scheduled actions at a time, so this is what the template will 
> look like in the end:
>
> [image: jhg.png]
>
> Here is what I coded: in models.py:
>
>
> class Node(models.Model):
> ID = models.DecimalField(max_digits=19, decimal_places=10)
> name = models.CharField(default='node', max_length=32)
> nb_solenoid = models.DecimalField(max_digits=19, decimal_places=10, 
> null=True, blank=True)
> connexion = models.CharField(max_length=255)
> status = models.BooleanField(default=False)
>
>
> class Firm(models.Model):
>
> name = models.CharField(max_length=32)
> address = models.CharField(max_length=32)
>
>
> class ScheduledAction(models.Model):
> date = models.DateTimeField(default=datetime.now, blank=True)
> firm = models.ForeignKey('Firm', on_delete=models.CASCADE, null=True, 
> blank=True)
> node = models.ForeignKey('Node', on_delete=models.CASCADE, null=True, 
> blank=True)
>
>
> views.py:
>
> def planification_view(request, id):
> obj = Firm.objects.get(id=id)
> form = ScheduledActionForm(request.POST or None)
> form1 = ScheduledActionForm(request.POST or None)
> form2 = FirmForm(request.POST or None)
> if form1.is_valid() and form2.is_valid():
> #form.save()
> print(type(form))
> print(form)
> context = {
> 'object': obj,
> 'form': form
> }
> return render(request, "node/planification.html", context)
>
>
> planification.html:
>
> 
> function submitForms(){
> document.forms["form1"].submit();
> document.forms["form2"].submit();
> }
> 
> 
> {{ object }}
> Firm: {{ object.name }}
> 
> 
> {% csrf_token %}
> {% for instance in object.node_set.all %}
>  {{ instance.name }}
> {% endfor %}
> 
> 
> 
> Planification
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
> 
> 
> Scheduled Actions
> {% for instance in object.scheduledaction_set.all %}
> {{instance.date}} - {{ instance.node }}
> {% endfor %}
> 
>
>
> But I can't go further and this code doesn't seem to work. I can check 
> nodes and click submit but nothing is stored in the database.
>
>
>
>

-- 
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/dc7287a1-0dfc-4bed-be96-0f2503e028e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how can I work with multi model forms

2018-12-27 Thread Ira Abbott
Hi,

Model forms have one model.  To have the form update fields in other models, 
you can overload form_valid in views so that it writes the addition form field 
to their respective models.

Ira

Sent from my iPhone

> On Dec 26, 2018, at 9:45 AM, Nur Mohsin  wrote:
> 
> Hi, in views.py form.save() is commented. Remove comment and try again. Then, 
> tell us what happens?
> 
>> On Wed, Dec 26, 2018 at 6:29 PM Tessnim Zrayga  
>> wrote:
>> Hello everyone,
>> I have this design: there's a firm, a firm can have multiple nodes. Each 
>> node can have many scheduled actions. What I'm trying to do is to create a 
>> template containing all informations about a firm and be able to create 
>> multiple scheduled actions at a time, so this is what the template will look 
>> like in the end:
>> 
>> 
>> 
>> Here is what I coded: in models.py:
>> 
>> 
>> 
>> class Node(models.Model):
>> ID = models.DecimalField(max_digits=19, decimal_places=10)
>> name = models.CharField(default='node', max_length=32)
>> nb_solenoid = models.DecimalField(max_digits=19, decimal_places=10, 
>> null=True, blank=True)
>> connexion = models.CharField(max_length=255)
>> status = models.BooleanField(default=False)
>> 
>> 
>> class Firm(models.Model):
>> 
>> name = models.CharField(max_length=32)
>> address = models.CharField(max_length=32)
>> 
>> 
>> class ScheduledAction(models.Model):
>> date = models.DateTimeField(default=datetime.now, blank=True)
>> firm = models.ForeignKey('Firm', on_delete=models.CASCADE, null=True, 
>> blank=True)
>> node = models.ForeignKey('Node', on_delete=models.CASCADE, null=True, 
>> blank=True)
>> 
>> views.py:
>> def planification_view(request, id):
>> obj = Firm.objects.get(id=id)
>> form = ScheduledActionForm(request.POST or None)
>> form1 = ScheduledActionForm(request.POST or None)
>> form2 = FirmForm(request.POST or None)
>> if form1.is_valid() and form2.is_valid():
>> #form.save()
>> print(type(form))
>> print(form)
>> context = {
>> 'object': obj,
>> 'form': form
>> }
>> return render(request, "node/planification.html", context)
>> 
>> planification.html:
>> 
>> function submitForms(){
>> document.forms["form1"].submit();
>> document.forms["form2"].submit();
>> }
>> 
>> 
>> {{ object }}
>> Firm: {{ object.name }}
>> 
>> 
>> {% csrf_token %}
>> {% for instance in object.node_set.all %}
>>  {{ instance.name }}
>> {% endfor %}
>> 
>> 
>> 
>> Planification
>> {% csrf_token %}
>> {{ form.as_p }}
>> 
>> 
>> 
>> 
>> Scheduled Actions
>> {% for instance in object.scheduledaction_set.all %}
>> {{instance.date}} - {{ instance.node }}
>> {% endfor %}
>> 
>> 
>> But I can't go further and this code doesn't seem to work. I can check nodes 
>> and click submit but nothing is stored in the database.
>> 
>> 
>> 
>> -- 
>> 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/5d2fd9de-991e-4526-8303-84287df0dfc2%40googlegroups.com.
>> 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/CAM0c9RqU7VW0B-BaR_O-ahqOTZEb9AXhc_ZUSaCd%2Bckqr3M9og%40mail.gmail.com.
> 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/43A15F92-0F2A-4077-A385-8AB912765252%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how can I work with multi model forms

2018-12-26 Thread Nur Mohsin
Hi, in views.py form.save() is commented. Remove comment and try again.
Then, tell us what happens?

On Wed, Dec 26, 2018 at 6:29 PM Tessnim Zrayga 
wrote:

> Hello everyone,
> I have this design: there's a firm, a firm can have multiple nodes. Each
> node can have many scheduled actions. What I'm trying to do is to create a
> template containing all informations about a firm and be able to create
> multiple scheduled actions at a time, so this is what the template will
> look like in the end:
>
> [image: jhg.png]
>
> Here is what I coded: in models.py:
>
>
> class Node(models.Model):
> ID = models.DecimalField(max_digits=19, decimal_places=10)
> name = models.CharField(default='node', max_length=32)
> nb_solenoid = models.DecimalField(max_digits=19, decimal_places=10, 
> null=True, blank=True)
> connexion = models.CharField(max_length=255)
> status = models.BooleanField(default=False)
>
>
> class Firm(models.Model):
>
> name = models.CharField(max_length=32)
> address = models.CharField(max_length=32)
>
>
> class ScheduledAction(models.Model):
> date = models.DateTimeField(default=datetime.now, blank=True)
> firm = models.ForeignKey('Firm', on_delete=models.CASCADE, null=True, 
> blank=True)
> node = models.ForeignKey('Node', on_delete=models.CASCADE, null=True, 
> blank=True)
>
>
> views.py:
>
> def planification_view(request, id):
> obj = Firm.objects.get(id=id)
> form = ScheduledActionForm(request.POST or None)
> form1 = ScheduledActionForm(request.POST or None)
> form2 = FirmForm(request.POST or None)
> if form1.is_valid() and form2.is_valid():
> #form.save()
> print(type(form))
> print(form)
> context = {
> 'object': obj,
> 'form': form
> }
> return render(request, "node/planification.html", context)
>
>
> planification.html:
>
> 
> function submitForms(){
> document.forms["form1"].submit();
> document.forms["form2"].submit();
> }
> 
> 
> {{ object }}
> Firm: {{ object.name }}
> 
> 
> {% csrf_token %}
> {% for instance in object.node_set.all %}
>  {{ instance.name }}
> {% endfor %}
> 
> 
> 
> Planification
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
> 
> 
> Scheduled Actions
> {% for instance in object.scheduledaction_set.all %}
> {{instance.date}} - {{ instance.node }}
> {% endfor %}
> 
>
>
> But I can't go further and this code doesn't seem to work. I can check
> nodes and click submit but nothing is stored in the database.
>
>
>
> --
> 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/5d2fd9de-991e-4526-8303-84287df0dfc2%40googlegroups.com
> 
> .
> 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/CAM0c9RqU7VW0B-BaR_O-ahqOTZEb9AXhc_ZUSaCd%2Bckqr3M9og%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


how can I work with multi model forms

2018-12-26 Thread Tessnim Zrayga
Hello everyone,
I have this design: there's a firm, a firm can have multiple nodes. Each 
node can have many scheduled actions. What I'm trying to do is to create a 
template containing all informations about a firm and be able to create 
multiple scheduled actions at a time, so this is what the template will 
look like in the end:

[image: jhg.png]

Here is what I coded: in models.py:


class Node(models.Model):
ID = models.DecimalField(max_digits=19, decimal_places=10)
name = models.CharField(default='node', max_length=32)
nb_solenoid = models.DecimalField(max_digits=19, decimal_places=10, 
null=True, blank=True)
connexion = models.CharField(max_length=255)
status = models.BooleanField(default=False)


class Firm(models.Model):

name = models.CharField(max_length=32)
address = models.CharField(max_length=32)


class ScheduledAction(models.Model):
date = models.DateTimeField(default=datetime.now, blank=True)
firm = models.ForeignKey('Firm', on_delete=models.CASCADE, null=True, 
blank=True)
node = models.ForeignKey('Node', on_delete=models.CASCADE, null=True, 
blank=True)


views.py:

def planification_view(request, id):
obj = Firm.objects.get(id=id)
form = ScheduledActionForm(request.POST or None)
form1 = ScheduledActionForm(request.POST or None)
form2 = FirmForm(request.POST or None)
if form1.is_valid() and form2.is_valid():
#form.save()
print(type(form))
print(form)
context = {
'object': obj,
'form': form
}
return render(request, "node/planification.html", context)


planification.html:


function submitForms(){
document.forms["form1"].submit();
document.forms["form2"].submit();
}


{{ object }}
Firm: {{ object.name }}


{% csrf_token %}
{% for instance in object.node_set.all %}
 {{ instance.name }}
{% endfor %}



Planification
{% csrf_token %}
{{ form.as_p }}




Scheduled Actions
{% for instance in object.scheduledaction_set.all %}
{{instance.date}} - {{ instance.node }}
{% endfor %}



But I can't go further and this code doesn't seem to work. I can check 
nodes and click submit but nothing is stored in the database.



-- 
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/5d2fd9de-991e-4526-8303-84287df0dfc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.