django-models

(Django) ORM in airflow - is it possible?

青春壹個敷衍的年華 提交于 2020-05-10 07:42:08
问题 How to work with Django models inside Airflow tasks? According to official Airflow documentation, Airflow provides hooks for interaction with databases (like MySqlHook / PostgresHook / etc) that can be later used in Operators for row query execution. Attaching the core code fragments: Copy from https://airflow.apache.org/_modules/mysql_hook.html class MySqlHook(DbApiHook): conn_name_attr = 'mysql_conn_id' default_conn_name = 'mysql_default' supports_autocommit = True def get_conn(self): """

AttributeError: module Django.contrib.auth.views has no attribute

≯℡__Kan透↙ 提交于 2020-05-10 06:54:32
问题 In my Django app useraccounts, I created a Sign-Up form and a model for my Sign-up. However, when I went to run python manage.py makemigrations, I encounter the error: AttributeError: module Django.contrib.auth.views has no attribute 'registration'. Secondly, am I coding the SignUpForm in forms.py correctly? I did not want to use the User model in models because it would request username and I didn't want my website to ask for a username. Here is my code: models.py from django.db import

Django Model Method or Calculation as Field in Database

|▌冷眼眸甩不掉的悲伤 提交于 2020-05-10 05:22:09
问题 Using Django ~=1.11 and Python 3.6 I need to store 'calculated' variables as fields in the Django model database. Here's a model: from django.db import models from datetime import date class Person(model.Model) "Last Name" last_name = models.CharField(max_length=25) "Birthday" birth_date = models.DateField() "City of birth" city_of_birth = models.CharField(max_length=25) I am creating a Unique ID using these fields. Specifically, I'm conjoining parts of each field into one string variable

How to generate random numbers in django

感情迁移 提交于 2020-05-10 04:25:45
问题 I want to generate automatic random numbers in a blank field while saving it in django. EDIT The random numbers must be unique. 回答1: EDIT: Changed solution to make random number unique and to use Django's make_random_password function. Note the below assumes you are storing the random number in a field called temp_password in a model UserProfile that is an extension of the User model. random_number = User.objects.make_random_password(length=10, allowed_chars='123456789') while User.objects

This QueryDict instance is immutable

一笑奈何 提交于 2020-05-10 04:25:39
问题 I have a Branch model with a foreign key to account (the owner of the branch): class Branch(SafeDeleteModel): _safedelete_policy = SOFT_DELETE_CASCADE name = models.CharField(max_length=100) account = models.ForeignKey(Account, null=True, on_delete=models.CASCADE) location = models.TextField() phone = models.CharField(max_length=20, blank=True, null=True, default=None) create_at = models.DateTimeField(auto_now_add=True, null=True) update_at = models.DateTimeField(auto_now=True, null=True) def

Django - form.save() is not creating ModelForm

左心房为你撑大大i 提交于 2020-05-04 05:31:52
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

Django - form.save() is not creating ModelForm

强颜欢笑 提交于 2020-05-04 05:30:26
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

Django - form.save() is not creating ModelForm

我怕爱的太早我们不能终老 提交于 2020-05-04 05:29:31
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

Django Error: Cannot use ImageField because Pillow is not installed

*爱你&永不变心* 提交于 2020-04-30 10:39:01
问题 I'm currently learning how to use Django to develop a web service. As I go through an online course on Udemy, I ran into a problem using ImageField in models.py. My problem is that, when I excute the runserver command, Django shows the following error although I am pretty sure the library Pillow is installed. In models.py, I have the following code: from django.db import models from django.contrib.auth.models import User class UserProfileInfo(models.Model): user = models.OneToOneField(User,

Django Error: Cannot use ImageField because Pillow is not installed

会有一股神秘感。 提交于 2020-04-30 10:37:30
问题 I'm currently learning how to use Django to develop a web service. As I go through an online course on Udemy, I ran into a problem using ImageField in models.py. My problem is that, when I excute the runserver command, Django shows the following error although I am pretty sure the library Pillow is installed. In models.py, I have the following code: from django.db import models from django.contrib.auth.models import User class UserProfileInfo(models.Model): user = models.OneToOneField(User,