O
O
Oleg2015-03-29 12:56:20
Django
Oleg, 2015-03-29 12:56:20

How to do many to many editing with additional fields in Django?

Good day
In general, you need to create a menu from these dishes, but with dynamic prices (today a pie costs 5 rubles - 10 - the day after tomorrow 6.50, etc. according to the mood of the seller)
models.py

class Menu(models.Model):
    day = models.OneToOneField( Day )
    dishes = models.ManyToManyField( Dish, through='MenuDishes' )

class MenuDishes(models.Model):
    menu = models.ForeignKey(Menu)
    dish = models.ForeignKey(Dish)
    price = models.DecimalField(...)

views.py
class MenuCreate(CreateView):
    model = Menu
    ...

sample
{% extends "base.html" %}

{% block content %}
    <form method="POST">
        {% csrf_token %}
        {{form}}
        <input type="submit" value="{{submit_text}}">
    </form>
{% endblock content %}

Only the day selection is displayed, and multiple select to select dishes... How can I make the price field appear?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2015-03-29
@LastDreamer

Answer suggested here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question