django-models

`objects.get(…)` does not work as expected

大憨熊 提交于 2020-01-15 15:39:09
问题 I'm trying to get an object from my neo4j database using neo4django >>> # There is a single Person object in the database, so I get a value >>> slug=Person.objects.get().name_slug >>> print(slug) doe-john >>> # ok, it's there >>> p=Person.objects.get(name_slug=slug) Traceback (most recent call last): File "<console>", line 1, in <module> File "/[...]/src/neo4django/neo4django/db/models/manager.py", line 37, in get return self.get_query_set().get(*args, **kwargs) File "/[...]/lib/python2.7

Django - How to link to a legacy database via intermediary?

▼魔方 西西 提交于 2020-01-15 14:07:43
问题 I have to integrate a legacy design with my Django project and I am looking for some advice on using an intermediary. The existing design works but now I need to filter the Project by a third table. In english - I have a Organization (Django) and which points to many Projects (Legacy). But all of the Project don't refer to that Organization. I have a third table ProjectMap which was build via a Trigger to address that. It corresponds the Organization.name to a project. How do I glue this

Django - How to link to a legacy database via intermediary?

若如初见. 提交于 2020-01-15 14:06:16
问题 I have to integrate a legacy design with my Django project and I am looking for some advice on using an intermediary. The existing design works but now I need to filter the Project by a third table. In english - I have a Organization (Django) and which points to many Projects (Legacy). But all of the Project don't refer to that Organization. I have a third table ProjectMap which was build via a Trigger to address that. It corresponds the Organization.name to a project. How do I glue this

Django - How to link to a legacy database via intermediary?

天大地大妈咪最大 提交于 2020-01-15 14:05:21
问题 I have to integrate a legacy design with my Django project and I am looking for some advice on using an intermediary. The existing design works but now I need to filter the Project by a third table. In english - I have a Organization (Django) and which points to many Projects (Legacy). But all of the Project don't refer to that Organization. I have a third table ProjectMap which was build via a Trigger to address that. It corresponds the Organization.name to a project. How do I glue this

Django: Return serializer ValidationError in Model save() method

最后都变了- 提交于 2020-01-15 09:36:09
问题 I use django-rest-framework to create Rest API within Django framework. And it's possible to return any validationError beside serializer methods. But, I was wondering is it possible to return errors from save() method of django model that be translated to django rest validationError ? For example imagine I want to limit creating objects on a specific table. like this: class CustomTable(models.Model): ... # modles fields go here def save(): if CustomTable.objects.count() > 2: # Return a

Django multiple annotate slows down the query

自古美人都是妖i 提交于 2020-01-15 03:59:29
问题 I have been debugging with django debug_toolbar , if I use more than one annotate in query then it takes a lot of time for Django to fetch the query results. class Project_First(models.Model): project_first_results_M2M = models.ManyToManyField(Project_First_Results) class Project_Second(models.Model): project_second_results_M2M = models.ManyToManyField(Project_Second_Results) class Project(models.Model): project_first_M2M = models.ManyToManyField(Project_First) project_second_M2M = models

Django multiple annotate slows down the query

你离开我真会死。 提交于 2020-01-15 03:59:07
问题 I have been debugging with django debug_toolbar , if I use more than one annotate in query then it takes a lot of time for Django to fetch the query results. class Project_First(models.Model): project_first_results_M2M = models.ManyToManyField(Project_First_Results) class Project_Second(models.Model): project_second_results_M2M = models.ManyToManyField(Project_Second_Results) class Project(models.Model): project_first_M2M = models.ManyToManyField(Project_First) project_second_M2M = models

Django 1.9 URLField removing the necessary http:// prefix

流过昼夜 提交于 2020-01-15 03:41:29
问题 I've seen a bunch of questions about this, but havent found an answer yet. This is my models: class UserProfile(models.Model): user = models.OneToOneField(User) . . . website = models.URLField(max_length=100, blank=True, null=True) and my forms.py: class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile fields = ('website') def clean_website(self): website = self.cleaned_data['website'] if website and not website.startswith('http://'): website = 'http://' + website return

return float(value) ValueError: could not convert string to float in Django models

丶灬走出姿态 提交于 2020-01-15 03:34:08
问题 I try to makemigrations / migrate on this Django models : from django.db import models from myapp.models import Site class GscElement(models.Model): ctr = models.FloatField('Taux de clic', default=0.0) impressions = models.IntegerField('Nombre d\'impressions', default=0) position = models.FloatField('Position moyenne', default=0.0) clicks = models.IntegerField('Nombre de clics', default=0) site = models.ForeignKey( Site, models.SET_NULL, blank=True, null=True ) class Page(GscElement): page

Django Many to Many Relationship With Another Field

流过昼夜 提交于 2020-01-15 03:30:08
问题 I have two models, Recipe and Ingredient . The Recipe model has a manytomany relationship with Ingredients, but I also need to be able to specify the quantity of the ingredients. My models currently look like: class Ingredient(models.Model): name = models.CharField(max_length="256", db_index=True, null=True) class Recipe(models.Model): ... ingredients = models.ManyToManyField(Ingredient, related_name="RecipeIngredients", db_index=True) But obviously each recipe will have different quantities