mysociety / django-images Goto Github PK
View Code? Open in Web Editor NEWAttach images to any Django model, with helpful admin
Attach images to any Django model, with helpful admin
Hello there:
I'm using this mixin as follow, but I'm not entirely sure if I'm doing it right
This is the test
def test_organization_has_images(self):
organization = Organization.objects.create(name='La Cosa Nostra')
image = Image.objects.create(content_object=organization)
self.assertEqual(organization.primary_image(), image.image)
And when I run it I get this error:
Traceback (most recent call last):
File "/home/falvarez/Workspace/votainteligente-portal-electoral/popular_proposal/tests/organization_tests.py", line 15, in test_organization_has_images
self.assertEqual(organization.primary_image(), image.image)
File "/home/falvarez/.virtualenvs/vota/src/django-images/images/models.py", line 59, in primary_image
primary_image_model = self.primary_image_model()
File "/home/falvarez/.virtualenvs/vota/src/django-images/images/models.py", line 65, in primary_image_model
primary_images = [i for i in self.images.all() if i.is_primary]
AttributeError: 'Organization' object has no attribute 'images'
So, I decided to write a property for the Organization model
class Organization(PopoloOrganization, HasImageMixin):
_id = models.AutoField(primary_key=True)
@property
def images(self):
return Image.objects.filter(object_id=self._id)
Which does the job, but I'm not entirely sure if you meant the creation of that property or am I getting it all wrong?
Thanks for this code BTW. ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.