django-models

Filter intermediary ManyToMany django

老子叫甜甜 提交于 2020-02-25 06:28:47
问题 class Ingredient(Model): name = CharField(max_length=55, unique=True) def __str__(self): return self.name class Meta: ordering = ('name',) class Product(Model): name = CharField(max_length=55) def __str__(self): return self.name class Meta: ordering = ('name', ) class ProductIngredient(Model): product = ForeignKey(Product, on_delete=CASCADE, related_name='product_ingredients') ingredient = ForeignKey(Ingredient, on_delete=CASCADE) optional = BooleanField(default=False) class Meta: unique

Django: ValueError at/ “The view To_do_list_app.views.home didn't return an HttpResponse object. It returned None instead.”

蹲街弑〆低调 提交于 2020-02-23 07:40:10
问题 Please, I am a newbie, if I didn't ask my question well, let me know. I am working on a To-Do List app. Anytime, I add a new task and time to the form on my web app and submit, I get the following error: ValueError at / The view To_do_list_app.views.home didn't return an HttpResponse object. It returned None instead. Below is my views.py file from django.http import HttpResponse from django.shortcuts import render,redirect from .forms import ListForm from .models import List def home(request)

Django Admin: change displayed column name in inline ManyToMany field

大兔子大兔子 提交于 2020-02-21 21:27:15
问题 I try to translate Django Admin site and I have a problem with ManyToMany TabularInline . My models.py are: class Doctor(models.Model): (...) specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje') class Meta: verbose_name = 'Lekarz' verbose_name_plural = 'Lekarze' class Specialization(models.Model): name = models.CharField(max_length=191, verbose_name='Nazwa') class Meta: verbose_name = 'Specjalizacja' verbose_name_plural = 'Specjalizacje' And my

Django Admin: change displayed column name in inline ManyToMany field

倾然丶 夕夏残阳落幕 提交于 2020-02-21 21:21:13
问题 I try to translate Django Admin site and I have a problem with ManyToMany TabularInline . My models.py are: class Doctor(models.Model): (...) specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje') class Meta: verbose_name = 'Lekarz' verbose_name_plural = 'Lekarze' class Specialization(models.Model): name = models.CharField(max_length=191, verbose_name='Nazwa') class Meta: verbose_name = 'Specjalizacja' verbose_name_plural = 'Specjalizacje' And my

Django Admin: change displayed column name in inline ManyToMany field

旧巷老猫 提交于 2020-02-21 21:20:38
问题 I try to translate Django Admin site and I have a problem with ManyToMany TabularInline . My models.py are: class Doctor(models.Model): (...) specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje') class Meta: verbose_name = 'Lekarz' verbose_name_plural = 'Lekarze' class Specialization(models.Model): name = models.CharField(max_length=191, verbose_name='Nazwa') class Meta: verbose_name = 'Specjalizacja' verbose_name_plural = 'Specjalizacje' And my

Error: pkg_resources.DistributionNotFound: The 'django==1.9.1' distribution was not found

↘锁芯ラ 提交于 2020-02-08 03:07:16
问题 I am getting following error trace when I am trying to run server in python environment: Traceback (most recent call last): File "/home/web/.virtualenvs/kolibri/bin/kolibri", line 5, in <module> from pkg_resources import load_entry_point File "/home/web/.virtualenvs/kolibri/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2927, in <module> @_call_aside File "/home/web/.virtualenvs/kolibri/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2913, in _call_aside

Overriding Django auto_now in datefiled

邮差的信 提交于 2020-02-07 05:14:14
问题 Is there a way to pass a date to datafield that overrides auto_now? I want to only use auto_now if a date is not passed. 回答1: According to the docs: Note that the current date is always used; it’s not just a default value that you can override. https://docs.djangoproject.com/en/2.0/ref/models/fields/#datefield So just don't use auto_now, use default, for example: from django.utils import timezone class YourModel(models.Model): date_approved = models.DateField(default=timezone.now) 来源: https:/

Overriding Django auto_now in datefiled

℡╲_俬逩灬. 提交于 2020-02-07 05:13:26
问题 Is there a way to pass a date to datafield that overrides auto_now? I want to only use auto_now if a date is not passed. 回答1: According to the docs: Note that the current date is always used; it’s not just a default value that you can override. https://docs.djangoproject.com/en/2.0/ref/models/fields/#datefield So just don't use auto_now, use default, for example: from django.utils import timezone class YourModel(models.Model): date_approved = models.DateField(default=timezone.now) 来源: https:/

Overriding Django auto_now in datefiled

扶醉桌前 提交于 2020-02-07 05:13:04
问题 Is there a way to pass a date to datafield that overrides auto_now? I want to only use auto_now if a date is not passed. 回答1: According to the docs: Note that the current date is always used; it’s not just a default value that you can override. https://docs.djangoproject.com/en/2.0/ref/models/fields/#datefield So just don't use auto_now, use default, for example: from django.utils import timezone class YourModel(models.Model): date_approved = models.DateField(default=timezone.now) 来源: https:/

How to render an input field in a template bound to a model field in Django

自作多情 提交于 2020-02-04 22:57:16
问题 The problem seems so solvable yet it eludes me. Hope I am able to explain my predicament. I am trying to include a jQuery autocomplete in a form. The autocomplete itself is working fine. I am now trying to link it to a model which is something like this: models.py class SupplierCatchment(models.Model): supp = models.ForeignKey(Supplier.....) supp_area = models.ForeignKey(Country, ...) supp_remarks = models.CharField(max_length=150,...) For rendering the form, I am using a model form . Case 1: