Comments (14)
@pymarco I'm just seing this but AutoOneToOneField
won't create a related object unless you try to access it.
a = Alpha.objects.create()
Beta.objects.count()
# 0
a.beta
# <Beta: Beta object>
Beta.objects.count() # 1
from django-annoying.
It is not working for me either.
class Alpha(models.Model):
...
class Beta(models.Model):
alpha = AutoOneToOneField(Alpha, primary_key=True, on_delete=models.CASCADE)
I created an Alpha
object and no corresponding Beta
object was created.
from django-annoying.
Hmm, can anyone see what the problem is, or submit a PR to fix it?
from django-annoying.
@arthurio thanks, its worked for me on Django 1.10, python 2.7
from django-annoying.
It is not working for me either.
django 1.9.7
annoying: 0.9.0
from django-annoying.
@littlehome-eugene We are going to need more details than that to figure out what is not working for you...
from django-annoying.
Same here. Django 1.11.2, annoying 0.10.3.
Under some circumstances objects are being created, but what those are I haven't figured out yet.
from django-annoying.
Not working for me either.
Django 1.11.6, python 2.7, annoying 0.10.3.
from django-annoying.
@eduardocesar @moorchegue I don't see how we can possibly help you without more details... Did you read my previous comment ?
from django-annoying.
@arthurio I've tried to access the related object after the creation of the primary object and did not appear. With some investigation, it seems that it was a boolean field in the related object that was preventing it's creation.
from django-annoying.
Doesn't work for me either:
class PatientRecord(models.Model):
checkup_interval = models.IntegerField(default=180)
class Patient(models.Model):
name = models.CharField(max_length=64)
# date_of_birth = models.DateField()
record = AutoOneToOneField(PatientRecord, on_delete=models.CASCADE)
registration_date = models.DateField()
last_visit = models.DateField(blank=True, null=True)
# Keep track of how many times we're sending messsages to people
# to make sure we don't spam them
appointment_reminder_attempt = models.IntegerField(default=0)
email_address = models.EmailField(blank=True, null=True)
Creating a Patient object does not automatically create a PatientRecord. I've tried creating via the admin as well as via the shell. Doesn't seem to work either way.
Django==2.0
django-annoying==0.10.3
from django-annoying.
@arthurio Thanks, accessing the related object creates it.
http://www.techinfected.net/2018/02/automatically-create-onetoonefield-in-django.html
from django-annoying.
Is primary_key=True required for this to work?
My model is defined as such:
class CrmCategory(models.Model):
stats_list_direct = AutoOneToOneField('CrmCategoryStatsList',
null = True,
related_name = 'direct_category',
help_text = 'What stats to list, as defined by this category directly.')
stats_list_union = AutoOneToOneField('CrmCategoryStatsList',
null = True,
related_name = 'union_category',
help_text = 'An or''ing of the direct stats, and the children''s stats_list_union')
And yet when I access it, I get a None:
cat = CrmCategory.objects.all().first()
print('union', cat.stats_list_union)
from django-annoying.
@albrnick You want to put the AutoOneToOneField
on the CrmCategoryStatsList
model instead:
class CrmCategoryStatsList(models.Model):
category = AutoOneToOneField(...)
from django-annoying.
Related Issues (20)
- Django 3.2 compatibility? HOT 1
- Django5 Support? HOT 3
- Possible to add support for types? HOT 4
- Can we get Pypi updated with the thread safe changes? HOT 1
- Test don't run against Django 1.7+ HOT 2
- Django 1.9 HOT 6
- Django 1.9: Cannot import name SingleRelatedObjectDescriptor HOT 4
- JSONField is not working in Django 1.9+
- Remove pretty-print from the JSON field output or make it configurable HOT 2
- Django 1.11 middleware HOT 3
- Please add a release with a universal wheel to PyPI HOT 1
- Could you publish a new release? HOT 4
- AutoOneToOneField breaks Django admin lookups HOT 5
- Using AutoOneToOneField with proxy model HOT 2
- Race Condition Fix HOT 3
- Setting HTTP status code when using ajax_request HOT 3
- ImportError: cannot import name 'six' HOT 2
- I know this is ancient history but a breaking change in a point release? HOT 6
- Support for django v3 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-annoying.