52π
β
The problem was a name clash.
Apparently when querying the DB I had:
objs = MyReport.objects.annotate(location=F('test__location'))
This added location
to the objects (didnβt see it in __dict__
, but maybe I just missed it). This means I could give up the property since I could call report_instance.location
. Of course, this means that all places that access MyReport I need to add the annotation (a special manager?).
π€mibm
4π
Just had a similar problem that seemed to be resolved by making sure I didnβt annotate with an alias that was the same name as the property I was trying to call.
π€GSchriver
- [Django]-What are the best practices to use AngularJS with Django
- [Django]-Auto-truncating fields at max_length in Django CharFields
- [Django]-ImportError: No module named virtualenv
3π
Add a setter method and the MyReport.location will be able to be set.
class MyReport(models.Model):
group_id = models.PositiveIntegerField(blank=False, null=False)
test = models.ForeignKey(Test, on_delete=models.CASCADE)
owner = models.ForeignKey(User, editable=False, default=get_current_user, on_delete=models.CASCADE)
user_objects = UserFilterManager()
_location = None
@property
def location(self):
if self._location is not None:
return self._location
return self.test.location
@location.setter
def location(self, value):
self._location = value
π€mazurekt
- [Django]-Debugging Apache/Django/WSGI Bad Request (400) Error
- [Django]-Django Rest Framework β Could not resolve URL for hyperlinked relationship using view name "user-detail"
- [Django]-Explicitly set MySQL table storage engine using South and Django
-1π
Try to ensure that test
is set:
@property
def location(self):
return self.test.location if self.test else None
π€Ihor Pomaranskyy
- [Django]-Assign variables to child template in {% include %} tag Django
- [Django]-Mixin common fields between serializers in Django Rest Framework
- [Django]-How to start doing TDD in a django project?
Source:stackexchange.com