django-models

GET products and images from two Django models, by filtering the product name and accessing the database only once

☆樱花仙子☆ 提交于 2020-12-15 05:23:39
问题 I have two Django models for an eCommerce website: class Product(models.Model): name=models.CharField(max_length=300) description=models.CharField(max_length=10000) class Thumnbnail(models.Model): thumnbnail=models.ImageField(null=True) product=models.ForeignKey(Product, related_name='related_product', on_delete=models.CASCADE) The user will input some keywords, and I filter on the product names with that keyword, and show only those products. With every product, on the results page, I want

GET products and images from two Django models, by filtering the product name and accessing the database only once

女生的网名这么多〃 提交于 2020-12-15 05:23:23
问题 I have two Django models for an eCommerce website: class Product(models.Model): name=models.CharField(max_length=300) description=models.CharField(max_length=10000) class Thumnbnail(models.Model): thumnbnail=models.ImageField(null=True) product=models.ForeignKey(Product, related_name='related_product', on_delete=models.CASCADE) The user will input some keywords, and I filter on the product names with that keyword, and show only those products. With every product, on the results page, I want

How to display the uploaded image using Django and AJAX

非 Y 不嫁゛ 提交于 2020-12-13 09:37:18
问题 I am creating a form that allows a user to select a image and upload it using Django and AJAX. This process works fine but the problem is that the uploaded image isn't being displayed on the screen however I did specify a div for it. These are the steps that I followed: Create a model that handle the uploaded image. Create a path for the function. Create the function that uploads the selected image. Create the template and AJAX function. models.py: class photo(models.Model): title = models

How to display the uploaded image using Django and AJAX

倖福魔咒の 提交于 2020-12-13 09:37:01
问题 I am creating a form that allows a user to select a image and upload it using Django and AJAX. This process works fine but the problem is that the uploaded image isn't being displayed on the screen however I did specify a div for it. These are the steps that I followed: Create a model that handle the uploaded image. Create a path for the function. Create the function that uploads the selected image. Create the template and AJAX function. models.py: class photo(models.Model): title = models

in my django project i get a 'ModelFormOptions' object has no attribute 'concrete_model' error

五迷三道 提交于 2020-12-13 04:01:13
问题 I have added a form for my django rest project. However, I keep getting a 'ModelFormOptions' object has no attribute 'concrete_model' error. In my User class I have added a new field 'password' and I was trying to create a form. and call the serializer upon it. My Model: class User(models.Model): gender = models.CharField(max_length=10, blank=False, choices=GENDER) first_name = models.CharField(max_length=20, blank=False) last_name = models.CharField(max_length=20, blank=False) position =

in my django project i get a 'ModelFormOptions' object has no attribute 'concrete_model' error

孤街醉人 提交于 2020-12-13 04:00:45
问题 I have added a form for my django rest project. However, I keep getting a 'ModelFormOptions' object has no attribute 'concrete_model' error. In my User class I have added a new field 'password' and I was trying to create a form. and call the serializer upon it. My Model: class User(models.Model): gender = models.CharField(max_length=10, blank=False, choices=GENDER) first_name = models.CharField(max_length=20, blank=False) last_name = models.CharField(max_length=20, blank=False) position =

How to rename only some items in values() in Django?

假如想象 提交于 2020-12-13 03:16:22
问题 Like the title says I need to rename some items in a queryset. The code for the queryset is made like this: data = SnpsFunctionalelement.objects.values('snpid__rsid', 'elementid__name', 'celllineid__name', 'countexperiments', 'filetype') i tried to rename the values using from django.db.models import F but if I do data = SnpsFunctionalelement.objects.values(rsid=F('snpid__rsid'), FunctionalElement=F('elementid__name'), CellLine=F('celllineid__name'), countexperiments=F('countexperiments'),

Dropdown select option to filter a Django list

…衆ロ難τιáo~ 提交于 2020-12-12 01:47:27
问题 Coming from Angular, this was easy to do, but I am not sure where to begin on creating a dropdown form that will filter from a list of objects. Basically, I have the code below, that will pull in and display all real estate listings; I would like to create a dropdown that will have 2 selections, 'Featured' and 'New Listing' and when a user selects one, the list will filter out and display only those listings that match. Thank you for your help. Here is my model from django.db import models

Dropdown select option to filter a Django list

我的未来我决定 提交于 2020-12-12 01:47:09
问题 Coming from Angular, this was easy to do, but I am not sure where to begin on creating a dropdown form that will filter from a list of objects. Basically, I have the code below, that will pull in and display all real estate listings; I would like to create a dropdown that will have 2 selections, 'Featured' and 'New Listing' and when a user selects one, the list will filter out and display only those listings that match. Thank you for your help. Here is my model from django.db import models

Filtering django DatetimeField__date not working

对着背影说爱祢 提交于 2020-12-08 08:38:22
问题 According to this document that was added on v1.9 we can able to query a DateTimeField by date without time. Examples are: Entry.objects.filter(pub_date__date=datetime.date(2005, 1, 1)) Entry.objects.filter(pub_date__date__gt=datetime.date(2005, 1, 1)) But it is not working for me: class MilkStorage(models.Model): .... created_at = models.DateTimeField(null=False) Usage from datetime import date MilkStorage.objects.filter(created_at__date=date.today()) It returns an empty queryset <QuerySet [