django-models

how to switch to a new database

僤鯓⒐⒋嵵緔 提交于 2020-07-19 06:19:51
问题 I want to deploy my django project to the production environments, and associated it with an new empty database, and I did as follows : Create an new empty database Updated settings.py and pointed the database name to the new one Deleted the migrations folder under my App Run python manage.py runserver and no errors returned Run python manage.py makemigrations and python manage.py migrate but only auth related tables created ( like auth_user , auth_group ... ), no databases tables created for

Disable Choice In ModelMultipleChoiceField CheckBoxSelectMultiple Django

倾然丶 夕夏残阳落幕 提交于 2020-07-15 15:17:06
问题 All, I have researched this for a couple of days, and can't quite seem to find what I'm looking for. I am well aware of using the following to disable a field in a Django form: self.fields['author'].disabled = True The above will disable a field entirely. I am trying to display a checkbox with multiple select options, but I want one of the choices to be automatically selected and disabled so the user can not change it as one of the choices they have selected. Here is the code that I've been

Tracking changes to Django Model instances

谁都会走 提交于 2020-07-15 00:57:26
问题 When you create or modify an object instance in Django's admin, a changelog entry is created. This is really nice for fairly obvious reasons. However my model's instances created by a normal user outside of the admin interface. No changelog is recorded to note its creation (not a huge issue) but I would like to track edits the user makes. I also want to show the user this full log (user+admin edits) in the frontend so I need a way to pull the changelog out. My question: how? Is there a one

Remove previous image from media folder when ImageFiled entry modified in Django

笑着哭i 提交于 2020-07-11 05:37:31
问题 I have a Model with a ImageField. class Photo(models.Model): ---- image = models.ImageField(verbose_name=_('Image'),upload_to='images/category/%Y/%m/%d/', max_length=200,null=True,blank=True) --- I edited this model and changed the image field by uploading a new image. My question, Is there a way to delete the previous image from its directory(from media folder) when I updates this entry with new image. I am using django 1.4.3 . 回答1: You can either use django's signals or simply overwrite the

upload multiple images without forms in django

本秂侑毒 提交于 2020-07-10 10:28:15
问题 This is my models.py class Upload(models.Model): images = models.ImageField(upload_to='image/') serializers.py class UploadSerializer(serializers.ModelSerializer): class Meta: model = Upload fields = '__all__' views.py class UploadViewSet(viewsets.ModelViewSet): queryset = Upload.objects.all() permission_classes = [ permissions.AllowAny ] serializer_class = UploadSerializer I can successfully upload single image, however django model is not recieving multiple images at once. How to upload

Django rest framework i want the Json to be displayed by clubbing the risk tag key with in rest api code

試著忘記壹切 提交于 2020-07-10 10:27:22
问题 Below is the Json response from Django Rest api i want a customized output like risktag: "common" as one group and risktag: "Supply chain" as one group' and the other 'risktag' type as one group at present when i hit the url http://127.0.0.1:8000/inidcator/?name=app&year=2019 below is the json response [ { "id": 1, "year": "2019-09-28", "name": "Mango", "risk": "Global markets for....", "risktag": "Common" }, { "id": 2, "year": "2019-09-28", "name": "Banana", "risk": "Global markets for the .

Traverse multiple foreign keys in Django DetailView

ぃ、小莉子 提交于 2020-07-10 08:43:05
问题 I'm working on a project to record all scores shot at a bunch of archery events. They are shot by many people at many events and many different archery rounds. (A "round" in archery is a particular type of competition. For the sake of simplicity let's say there are two: indoor and outdoor.) Here's a basic ER diagram of the relevant part of my database model: ┌───────────┐ ┌───────────┐ ┌────────────────┐ ┌───────────┐ │ │ ╱│ │╲ │ │╲ │ │ │ Person │──────┼──│ Score │──┼────│ EventRound │──┼────

How to run my view periodically till some end date?

一个人想着一个人 提交于 2020-07-10 06:45:47
问题 I have a model for running the scrapy tasks. Now the view returns scrapped results after some time. There is no any use of two fields search_frequency and scraping_end_date for now. This fields will be used to run the scrapy view till the scraping_end_date at the given search_frequency value. For this problem How can I solve? Which approach will be better ? Is django only will be sufficient for this task? Any suggestions will be helpful. my model looks like this class Task(models.Model): task

django.db.utils.IntegrityError: NOT NULL constraint failed: users_profile.user_id

烈酒焚心 提交于 2020-07-10 03:43:05
问题 I am currently working on a project that would take in a users information and store it. My problem is I keep running into this NOT NULL constraint failed with the user id error. I believe this comes from having a null user when the form is trying to save, but don't know what I could do to fix it. I tried using this line: form.user = Profile.objects.get(user=self.request.user) but it didn't work and gave me this error: NameError at /users/pii/ name 'self' is not defined Any help or advice

Prevent any CRUD functionality on a django model

大城市里の小女人 提交于 2020-07-09 12:08:05
问题 Hello Im currently using a third party package called django-river to implement a sort of workflow system into my application. The reason for using this is because it allows the user to dynamically generate workflows and attatch functions on the fly . Im currently using this across some of my models that require this functionality. However , there is one model that i wish to restrict this freedom. I do not wish to allow the user to add any instances than the one i have added from the start ,