django-models

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils'

旧城冷巷雨未停 提交于 2020-01-15 01:48:47
问题 Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1 I configured using the official installation guide. enter code here $ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self.

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils'

ぃ、小莉子 提交于 2020-01-15 01:48:07
问题 Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1 I configured using the official installation guide. enter code here $ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self.

How can I create an inherited django model instance from an existing base model instance?

别等时光非礼了梦想. 提交于 2020-01-15 01:23:25
问题 I have two django models like these: class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) class Restaurant(Place): serves_hot_dogs = models.BooleanField() serves_pizza = models.BooleanField() I had previously created a Place instance, like this: sixth_ave_street_vendor = Place(name='Bobby Hotdogs', address='6th Ave') sixth_ave_street_vendor.save() Now bobby has upgraded his street vendor to a restaurant. How can I do that in my code?! Why

Import data into Django model with existing data?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 13:14:27
问题 I'm working on an online form builder tool (specifically for insurance agents). One of the things we would like to offer our customers is to have pre-built forms for common products (auto, home, life, etc) be available by default, but still modifiable. Under normal circumstances, I would simply create the forms in my development environment, then create a fixture containing these forms, and run syncdb on all the live sites. Unfortunately that isn't a possibility, as some of our customers

Import data into Django model with existing data?

风流意气都作罢 提交于 2020-01-14 13:12:17
问题 I'm working on an online form builder tool (specifically for insurance agents). One of the things we would like to offer our customers is to have pre-built forms for common products (auto, home, life, etc) be available by default, but still modifiable. Under normal circumstances, I would simply create the forms in my development environment, then create a fixture containing these forms, and run syncdb on all the live sites. Unfortunately that isn't a possibility, as some of our customers

Admin Site appending letter “s” to end of each model\table name on Django

微笑、不失礼 提交于 2020-01-14 07:57:08
问题 I tried the verbose name when registering it on my admin.py so that it would appear as Data instead of Datas but that did not work. admin.site.register(Data, verbose_name="Data") Any ideas? 回答1: You should be setting verbose_name_plural in that case. Docs here. Also you should be setting it on the model's Meta options of your model (docs here). Example: class MyModel(models.Model): # my fields class Meta: verbose_name_plural = "PluralForMyModel" 来源: https://stackoverflow.com/questions

Django: foreign key queries

这一生的挚爱 提交于 2020-01-14 07:37:10
问题 I'm learning Django and trying to get the hang of querying foreign keys across a bridging table. Apologies if this is a duplicate, I haven't been able to find the answer by searching. I've got models defined as follows class Place(models.Model): id = models.IntegerField(primary_key=True) name = models.CharField(max_length=100) class PlaceRef(models.Model): place = models.ForeignKey(Place) # many-to-one field entry = models.ForeignKey(Entry) # many-to-one field class Entry(models.Model): id =

Auto Generated Slugs in Django Admin

血红的双手。 提交于 2020-01-14 05:57:09
问题 I have an app that will one day allow front-end crud, which will create the slug with slugify . Right now though, all the object creation is being done in the admin area and I was wondering if there is a way to auto generate slugs while creating and saving an object from within admin? Here is the method for slugify for the front-end; not sure if its even relevant. Thank you. def create_slug(instance, new_slug=None): slug = slugify(instance.title) if new_slug is not None: slug = new_slug qs =

Cannot get Django 1.7 Migrations to detect proper changes to my DB.

旧时模样 提交于 2020-01-14 04:59:06
问题 I have a production web project running with a decent amount of data in the MySQL db. I am trying to update the database with some changes to an app called "enterlink." I've made new elements in the existing models and created new models altogether. Before this migration, I have never touched the schema of the db since originally running syncdb to create it. When I run: "python manage.py makemigrations enterlink" the below output appears(pic). My question is, why is this happening? The DB

Django SearchVector on choices field

扶醉桌前 提交于 2020-01-14 04:51:05
问题 If I have a simple Django model like: from model_utils import Choices class Art(models.Model): CATEGORIES = Choices( (1, 'DIGITAL_ART', 'Digital Art'), (2, 'MULTIMEDIA', 'Multimedia'), ) title = models.TextField() category = models.PositiveSmallIntegerField( db_index=True, choices=CATEGORIES, blank=True, null=True ) How can I use SearchVector in postgres to allow for searching on both the title and categories fields? E.g. so "Some Book Digital Art" would query over both the title and