django-models

Django Data to JsonResponse

ⅰ亾dé卋堺 提交于 2020-01-16 09:06:08
问题 I have this model that store all my data. This is my model.py: from django.db import models class Showing(models.Model): movie_id = models.CharField(primary_key=True, max_length=11) movie_title = models.CharField(max_length=100) image_url = models.TextField(blank=True) synopsis = models.TextField(blank=True) rating = models.TextField(default="MTRCB rating not yet available") cast = models.CharField(max_length=100) release_date = models.CharField(max_length=50, blank=True) def __str__(self):

Django Data to JsonResponse

我们两清 提交于 2020-01-16 09:06:04
问题 I have this model that store all my data. This is my model.py: from django.db import models class Showing(models.Model): movie_id = models.CharField(primary_key=True, max_length=11) movie_title = models.CharField(max_length=100) image_url = models.TextField(blank=True) synopsis = models.TextField(blank=True) rating = models.TextField(default="MTRCB rating not yet available") cast = models.CharField(max_length=100) release_date = models.CharField(max_length=50, blank=True) def __str__(self):

Can not delete superuser in django and a resulting error django.db.utils.OperationalError: no such column: infrastructure_profile.slug

百般思念 提交于 2020-01-16 09:05:37
问题 I wanted to add a slug field to my model Profile (that extends the User model) after I had several profiles created, then an error appeared when reaching the profile page with the slug in the url saying : Django OperationalError: no such column: infrastructure_profile.slug so I looked here and saw this answer and it suggested I delete all my migrations files to restart the database , so I did and then I got the same error , so I thought I should delete all the users I already have that didn't

Integrating a teradata database with django models framework

独自空忆成欢 提交于 2020-01-16 09:03:08
问题 We have an external teradata reporting database which we want to create a frontend for generating and querying using django. I've gotten relatively far on just using a direct ODBC connection to the DB and running queries and displaying them on the website, but the further I get into it the more evident it is becoming that I really need to be using the django models framework. My question is does anyone have any experience or insight in how to integrate a teradata database into a django web

Query to fetch highest rated movie with mimimum 5 people rated

强颜欢笑 提交于 2020-01-16 08:35:50
问题 I want to fetch name of movie with maximum rated movie with minimum 5 people rated in django. My code : model.py class Movie(models.Model): id = models.AutoField(primary_key=True) title = models.CharField(max_length=100) vote_count = models.IntegerField() class Watchlist(models.Model): userid = models.IntegerField() movie_id = models.ForeignKey(Movie, on_delete=models.CASCADE) rating = models.IntegerField() what will be query to get movie with highest rating with minimum 5 people ? 回答1: I

Why does cloning this subclass of FloatField (with added validators) throw an exception?

人走茶凉 提交于 2020-01-16 04:00:12
问题 I am new to Python and Django. I want my model to have range-validated floats. From this answer I wrote this: class FloatRangeField (FloatField): """A FloatField constrained to a given range.""" def __init__ (self, minimum, maximum, **kwargs): minmax = [MinValueValidator (minimum), MaxValueValidator (maximum)] print ("\n\t\tFloatRangeField({},{})".format(minimum,maximum)) # (A) FloatField.__init__ (self, validators = minmax, **kwargs) print ("\t\tFINISHED\n") This was causing errors in

In python how can I check to see if an object has a value?

走远了吗. 提交于 2020-01-16 03:29:18
问题 Base Account class BaseAccount(models.Model): user = models.ForeignKey(User, unique=True) def __unicode__(self): """ Return the unicode representation of this customer, which is the user's full name, if set, otherwise, the user's username """ fn = self.user.get_full_name() if fn: return fn return self.user.username def user_name(self): """ Returns the full name of the related user object """ return self.user.get_full_name() def email(self): """ Return the email address of the related user

Composite keys in Django Rest Framework?

余生长醉 提交于 2020-01-16 01:12:11
问题 I've been working on a Django app for tracking VLAN usage in multiple network environments, which would be used by other apps to allocate VLANs for new installations. The model is a hierarchy: Location->VLANPool->VLAN So there is a unique VLAN 100 at each location, which could be a member of a different pool, depending on the location. Client applications can then say "give me the next VLAN in the customer_networks" pool, and then perform various operations on the resulting VLAN - reserve,

Override Django ImageField validation

☆樱花仙子☆ 提交于 2020-01-16 00:48:11
问题 I am trying to create a form where users will be allowed to upload any image file + SWF files. Django's ImageField does not support SWF so I need to override it. What I want to do is to check if the file is SWF, if True, return it. If it's not SWF, call the original method which will take care of the file validation. However, I am not sure how to implement that. Here is an example of what I am trying to achieve, but it does not work: from hexagonit import swfheader class SwfImageField(forms

Why is Django DecimalField attribute `max_digits` non-optional?

 ̄綄美尐妖づ 提交于 2020-01-16 00:34:28
问题 CommandError: System check identified some issues: ERRORS: (fields.E132) DecimalFields must define a 'max_digits' attribute. Is there a technical reason why max_digits is a required attribute for Django's model field DecimalField ? The docs say it used Python's [decimal][1] module, but python object type doesn't seem to be bothered at all by anything to do with the absolute number of digits of the decimal object. Maybe there's an opaque ORM reason? FloatFields (against which DecimalFields are