In Django forms, how do I set a field to read-only (or disabled) so that it cannot be edited?

In Django forms, how do I make fields read-only (or disabled)? When creating a new entry using a form, all fields should be enabled - however, some fields must be read-only when the record is in update mode. For example, when creating a new Item model, all fields must be editable, but when updating records, is there a way to disable the ...

Posted by Tonka1979 on Fri, 07 Feb 2020 00:42:47 -0800

ORM aggregate function details: Count

Count: used to find the number of data. The model used in all of the following examples is: from django.db import models # Define author model class Author(models.Model): name = models.CharField(max_length=100, unique=True) age = models.IntegerField() email = models.EmailField() c ...

Posted by digitalalpha on Mon, 03 Feb 2020 05:59:44 -0800

[Django] Django RestFramework framework

Install RestFramework $ pip install djangorestframework # settings.py INSTALLED_APPS = ( ... 'rest_framework', ) Create Serializer class from rest_framework import serializers from .models import Book, Author, Publisher class AuthorSerializer(serializers.Serializer): id = serializers.IntegerFie ...

Posted by CodeJunkie88 on Sun, 26 Jan 2020 06:50:58 -0800

Continue my login module development I

1. In the module in django, create the user class UserInfo(models.Model): name = models.CharField(max_length=20) email = models.CharField(max_length=50) power = models.IntegerField() phone = models.CharField(max_length=20) country = models.CharField(max_length=10) city = models.C ...

Posted by MathewByrne on Wed, 22 Jan 2020 00:57:09 -0800

Django framework: Model Association, properties of model class

1. correlation 1.1 model class relationship There are three types of relationships in relational databases: ForeignKey: one to many. Define the field in the multiple end. ManyToManyField: many to many, defining fields on either end. One to one field: one to one, define the field on either end. 1.1.1 one to many relationship #Define book mode ...

Posted by LiamProductions on Mon, 20 Jan 2020 10:15:24 -0800

Django and Vue develop web separately

@3 month concentrated essence Django and Vue joint project development Project environment construction 1. Build a virtual environment Virtual environment establishment 2. Install django Activate virtual environment, install Django, build myweb project pip installation slow reference: https://blog ...

Posted by webrajesh on Sat, 18 Jan 2020 05:01:20 -0800

Experience and skills summary of Python Django development

Article directory 1. Data transfer between front and back stations 2. Several common methods of interacting with database and returning data 3. Solutions of multiple buttons corresponding to one form 4. Form control and operation in HTML 5. Message frame message usage 6. Auto now, auto now add of Dat ...

Posted by Ilovetopk on Sat, 18 Jan 2020 04:11:04 -0800

Django Web framework teaching notes

Catalog Article directory Catalog Query data Field lookup query predicate Modify data record Delete record Aggregate query F object Q object - Q() Native database operation method Query data The query of database needs to use manager object Call the query interface through the MyModel.ob ...

Posted by BDKR on Thu, 16 Jan 2020 07:22:00 -0800

Django framework: design model

1. Design model We used to operate the database by writing sql statements. Can we operate the database without writing sql statements? Of course, it's time to use the ORM framework. 1.1 ORM framework O is object, which means class object, R is relation, translated into Chinese is relation, which means data table in relational database, M is map ...

Posted by pocobueno1388 on Wed, 15 Jan 2020 03:06:21 -0800

django2: routing path syntax

Catalog 1. Problem introduction 2. Use example 3.path converter 4. Custom converter 4.1 definition 4.2 registration 5. Use regular expressions 6.Import changes 7. Code rewriting 8. summary September 23. Django The 2.0a1 version has been rel ...

Posted by murali on Sun, 12 Jan 2020 01:50:56 -0800