django-models

Adapt an existing database to a django app

陌路散爱 提交于 2021-02-04 13:22:06
问题 I have a Postgresql databese with data. I want to create a django app with that database. How can i import the tables to django models and/or views? 回答1: There is a utility called manage.py inspectdb to generate models from your existing database. It works pretty well. $ python manage.py inspectdb > models.py 回答2: If your database is not very simple -- or very well designed -- you'll find it a poor fit with Django. While the reverse engineering works well, you may find that the original

Modifying Sign Up tab created using django framework

给你一囗甜甜゛ 提交于 2021-02-04 08:34:27
问题 I have made a sign up tab that registers new users and log in page that allows the registered users to continue with the site. I want if any registered user (having a registered email) tries to sign up again , an error message should pop up saying 'You are already having an account. Please Log in'. I stored the data(s) of registered user(s) in a table created in models.py named SignedUpUsers. Please help me achieve my task. models.py # Create your models here. class SignedUpUsers(models.Model

Adding custom field to django-notifications always returning none on notify.send()

China☆狼群 提交于 2021-01-29 21:02:16
问题 I am trying to add a new field to the Notification model in django-notifications-hq. Currently in my main/models.py i have: class Notification(AbstractNotification): # custom field example unique_uuid = models.CharField(max_length=255,unique=True, null=True) class Meta(AbstractNotification.Meta): abstract = False app_label = 'main' Now in my settings.py file I have: NOTIFICATIONS_NOTIFICATION_MODEL = 'main.Notification' NOTIFICATIONS_USE_JSONFIELD=True I am trying to generate a notification

I want to edit SizeProductMapping model using Django forms but The form is not rendering - Django

断了今生、忘了曾经 提交于 2021-01-29 19:51:06
问题 I am trying to create a edit form to update the database using Django model Forms but the problem is that edit form part of the sizeProductMap.html page is not rendering when edit form ( sizeProductMap_edit ) request is made. My models are as shown below. models.py class Product(models.Model): prod_ID = models.AutoField("Product ID", primary_key=True) prod_Name = models.CharField("Product Name", max_length=30, null=False) prod_Desc = models.CharField("Product Description", max_length=2000,

non trivial django serializer for a complex model

假如想象 提交于 2021-01-29 18:40:51
问题 After many years I code with Java, I got an interesting project at work to be developed using python django rest framework. I have a complex model, with many relations, in which I want to create entities in DB based on one JSON request. Please refer to attached screenshot of my DB model. My goal is to create new projects in the DB where I have set of companies in DB and a freelancer can suggest to a project of the company. I would like to get a JSON request that contains: company id (ALREADY

Adding custom field to django-notifications always returning none on notify.send()

十年热恋 提交于 2021-01-29 18:31:29
问题 I am trying to add a new field to the Notification model in django-notifications-hq. Currently in my main/models.py i have: class Notification(AbstractNotification): # custom field example unique_uuid = models.CharField(max_length=255,unique=True, null=True) class Meta(AbstractNotification.Meta): abstract = False app_label = 'main' Now in my settings.py file I have: NOTIFICATIONS_NOTIFICATION_MODEL = 'main.Notification' NOTIFICATIONS_USE_JSONFIELD=True I am trying to generate a notification

How to compute balance for each user separately as a field in django

荒凉一梦 提交于 2021-01-29 17:56:03
问题 I have three models the first is an account model the second is a subscription which is my cutomised model while the next is payment. Account model has a balance field I want to get the balance of each user in django admin panel byquering the total amount of payments done in the payments model minus the total subscription for each user differently .and display their balances. I am a begginner in django help me map this class Account(AbstractBaseUser): username = models.CharField(max_length=30

Limiting access to objects in Django

柔情痞子 提交于 2021-01-29 17:49:57
问题 I have a particular model and that model has finegrained access settings. Something like: class Document(models.Model): ... access = models.ManyToManyField(Group) Groups consist of particular tags, and those tags are linked to users. Long story short, one way or another the documents are only accessible by particular users. It is very important that this check does not slip through the cracks. So I can see a number of options. One is that every time I access a Document, I add the check:

Django Pass a Form's Field to a Model's Field

守給你的承諾、 提交于 2021-01-29 17:26:58
问题 I am learning Django web framework by going through this example. In one of the view functions: def renew_book_librarian(request, pk): """View function for renewing a specific BookInstance by librarian.""" book_instance = get_object_or_404(BookInstance, pk=pk) # If this is a POST request then process the Form data if request.method == 'POST': # Create a form instance and populate it with data from the request (binding): form = RenewBookForm(request.POST) # Check if the form is valid: if form

Django IntegrityError: null value in column “interestreceiver_id” of relation “HomeFeed_interest” violates not-null constraint

时光毁灭记忆、已成空白 提交于 2021-01-29 17:13:07
问题 Django : Why is my submit interest form not submitted because of an integrity error issue? Did I write my view or template wrongly? How should I solve this error as i've never encountered before. i searched on this website and saw some profile examples but mine is blog post and i dont really understand how their change could solve the error.. should it be 'obj.interestsender=user' and not 'object. interestreceiver=user' and whether i also need 'obj.interestreceiver=blog_post.author' in the