tags:

views:

21

answers:

1

Lets say I have this model

class Egg(models.Model):
    file = FileField(upload_to='media')
    img = ImageField(upload_to='media')

How to get an Egg instance if I only have the file URL string like 'http://example.com/media/spam.tar.gz'? Can I query by this URL??

+1  A: 

Which part of the url you want to query by? By spam.tar.gz? If so, you can try:

Egg.objects.filter(file__icontains='spam.tar.gz').
gruszczy
thanks, I didnt know that we can query a FileField by string.
kusut