Giter VIP home page Giter VIP logo

django-images's People

Contributors

mhl avatar evdb avatar dracos avatar

Stargazers

 avatar Jonathan Barratt avatar

Watchers

 avatar James Cloos avatar  avatar

django-images's Issues

How can I use the HasImageMixin?

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. ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.