Re: Models and relationships

2015-07-06 Thread Sadaf Noor
If you have at least one entry in contact with a valid location, then
it should work:

from app.models import Contact
> contact = Contact.all()[0]
> print contact.locationid.locationname


2015-07-06 18:04 GMT+06:00 Chris Strasser :

> Hi ,I am fairly new to Django and am struggling with models hope someone can 
> sort me out.
>
>
> Models:
> class Organization(models.Model):  #customer or vendor person or company
> orgid = models.AutoField(db_column='OrgID', primary_key=True)
> is_company = models.NullBooleanField(db_column='IsCompany', default =True)
> organizationname = models.CharField(db_column='OrgName', 
> max_length=75,blank=True, null=True)
> main_phone = models.CharField(db_column='MainPhone',max_length=20, 
> blank=True, null=True)
> ...
> ...
>
> class Location(models.Model):
> locationid = models.AutoField(db_column='LocationID', primary_key=True)
> orgid = models.ForeignKey(Organization, db_column='OrgID')
> locationname = models.CharField(db_column='LocationName', max_length=75, 
> null=True)
> address1 = models.CharField(db_column='Address1', max_length=200, 
> blank=True, null=True)
> ...
> ...
>
>  class Contact(models.Model):
> contactid = models.AutoField(db_column='ContactID', primary_key=True)
> locationid = models.ForeignKey(Location, db_column='LocationID')
> firstname = models.CharField(db_column='FirstName', 
> max_length=50,blank=True, null=True)
> lastname = models.CharField(db_column='LastName', 
> max_length=50,blank=True, null=True)
> ...
> ...
>
> my problem is with reverse lookups (i think it is called) the docs say that i 
> can access entries through blog.entry,(by lowercaseing the class)
> it appears to me that i have the same setup with contact and location but i 
> am getting errors ??
>
>
> what I am trying to do is access a contacts address and organization at both 
> the views level and the templates.(I would like to create a
> list of contacts, their company and their address ordered by contact name)
>
> if someone would point me in the right direction it would be greatly 
> appreciated.
>
> Thanks.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8abd757c-cd28-4c2f-82c9-ecd8c60dff4d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVrtQ%2BpUkdW-OsAk0vQEHrWynwAAfOxQHtn%3D7xJ0AsEdHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help me for create restful web services

2015-07-06 Thread Sadaf Noor
You can try Tastypie (https://django-tastypie.readthedocs.org/en/latest/)

2015-07-06 19:00 GMT+06:00 ywaghmare5203 :

> Hello All,
>
> I am working on Django 1.6.6 and I am to create a web services in the
> existing code. please tell me how to create a Restful web services using
> Django. I am beginner in python. please help me for web services creation
>
> Thanks,
>
> Yogesh Waghmare
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/811c0d56-1ed4-4dfc-867c-8f3b68ad813e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/811c0d56-1ed4-4dfc-867c-8f3b68ad813e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVqU50tHqtA1c8U99pgrVPLQeGfXEQrsqK%3DrnjTABZAG%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save base64 string in Python django

2015-07-14 Thread Sadaf Noor
If you can avoid saving images to database then the solution would look
like following where you are serving base64 url of image to reduce your
website data bandwidth:


   1. from django.db import models
   2. class Photo( models.Model ):
   3. title = models.CharField( max_length=255 )
   4. image = models.ImageField( upload_to="photos/", max_length=255)
   5. @property
   6. def image_url( self ):
   7. try:
   8. img = open( self.image.path, "rb")
   9. data = img.read()
   10. return "data:image/jpg;base64,%s" % data.encode('base64')
   11.
   12. except IOError:
   13. return self.image.url


2015-07-14 20:46 GMT+06:00 Bill Freeman :

> You don't show where the 'Image' object comes from (in Image.open), so I
> can't be specific, but here are some generalities:
>
> "Incorrect padding" is probably a message from the base 64 decoder.
> Capture your request.POST[photo] to play with separately.  If you are doing
> this under the development server you can add a pdb.set_trace() to get a
> prompt where you can play with things.  Alternatively, put the decode and
> the StringIO creation in separate statements so the the line generating the
> error will be clear.
>
> Are you sure that the image is base 64?  If it's coming from a file field
> in an HTML form, it probably isn't, which would explain the decode error
> (it I'm correct and it is a decoder error).
>
> It is customary to store images on the file system, putting only the path
> to the file in the database, as part of a model instance. That way the
> front end server (Apache or nginx, etc.) can serve the images without
> involving python and the database..  There are image oriented model fields
> available in django to facilitate this, see the excellent documentation.
>
> If, for whatever reason, you must store the image in the database, you can
> store it as a (binary) string.  If your image object makes the data
> available as a string, there will be no need to pump it through a StringIO
> object.
>
> On Mon, Jul 13, 2015 at 7:40 AM, ywaghmare5203 
> wrote:
>
>> Hello all,
>>
>> I am trying to save base64 string string image to database but I am not
>> able to store. I am beginner for python django language.
>>
>> I am following these steps:--
>>
>> from base64 import b64decode
>> from django.core.files.base import ContentFile
>> from time import time
>> import cStringIO
>> import base64
>>
>>
>> pic = cStringIO.StringIO()
>> image_string =
>> cStringIO.StringIO(base64.b64decode(request.POST['photo']))
>> image = Image.open(image_string)
>> image.save(pic, image.format, quality = 100)
>> pic.seek(0)
>> return HttpResponse(pic, content_type='image/jpeg')
>>
>> but I have error
>>
>> TypeError: Incorrect padding
>>
>> Please help me for store the base64 image string in the database.
>>
>>
>> Thanks & Regards,
>>
>> Yogesh Waghnare
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/54b12c7e-e9b0-4a47-85ce-988c897bbd11%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/54b12c7e-e9b0-4a47-85ce-988c897bbd11%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB%2BAj0v_qnReqeKyVib48_8qRGwo9Qs4LY%2BVn1iNX5DjAbVCcQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAB%2BAj0v_qnReqeKyVib48_8qRGwo9Qs4LY%2BVn1iNX5DjAbVCcQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https:

Re: Opening Django File

2015-07-14 Thread Sadaf Noor
There is a thing called IDE:
https://en.wikipedia.org/wiki/Integrated_development_environment

PyCharm (https://www.jetbrains.com/pycharm/) is my personal fevorite,
Cheers!


2015-07-14 20:23 GMT+06:00 Great Avenger Singh :

> On Tue, Jul 14, 2015 at 2:45 PM, Chaitanaya Sethi
>  wrote:
>
> > I have created a django file.
> > How to open it, the place where code can be edited?
>
> Question seems very vague. Django files are mostly Python Files with
> .py extension, So you can use any editor. or be more specific to your
> question.
>
>
> --
>
> Thanks
> Arshpreet Singh
>
> I am Sikh boy, Learning by doing and Learning by teaching is my religion.
>
> --
> Slashdot TV.
> Video for Nerds.  Stuff that matters.
> http://tv.slashdot.org/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAstK2Ed5OQ%2BpY8LL28BqW4LWE2peAni2mdhfZp%3DrwOjQ8r%3DuA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVrfD9ndFJ7LcVYntWEmht4JGamy8t%3DEvwY1X19HuEBJuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Development Server Ignores IP-address Parameter

2015-07-16 Thread Sadaf Noor
Actually if you run your django at 0.0.0.0:8000 at your server pc which has
a ip 192.168.0.102 <http://192.168.0.102:8001/>

> ./manage.py runserver 0.0.0.0:8000


then from another pc of the same network (as 192.168.0.102
<http://192.168.0.102:8001/> is a local ip) if you type http://
<http://server_Ip>192.168.0.102 <http://192.168.0.102:8001/>  then it will
show your desired website.

2015-07-16 7:21 GMT+06:00 :

> For some reason, my Django Development Server ignores the IP:Port
> parameter when I start it. No matter what I enter for that parameter, it
> always uses 127.0.0.1:8000.  I think (but am not sure) this started
> happening when I upgraded from Django-1.7 to Django-1.8.2.
>
> I am running on Slackware Linux, I have not noticed this problem until
> recently.  It definitely worked correctly several months ago.
>
> At the bottom of this message, I show how I launch the server,
> and the response it gives in my console. No matter what IP:Port
> I request, I always get 127.0.0.1:8000.
>
> How can I fix this problem?
>
> Thanks.
> 
> I start the development server with the following command:
>
>   % python  manage.py runserver  192.168.0.102:8001
>
> The following reply appears on the console:
>
>   /usr/local/lib/python3.3/importlib/_bootstrap.py:313:
> RemovedInDjango19Warning: django.utils.importlib will be removed in Django
> 1.9.
>   return f(*args, **kwds)
>
>   Performing system checks...
>
>   System check identified no issues (0 silenced).
>   July 15, 2015 - 17:45:10
>   Django version 1.8.2, using settings 'app3.settings'
>   Starting development server at http://127.0.0.1:8000/
>   Quit the server with CONTROL-C.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a695a746-618a-46a2-a216-180577e829ac%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a695a746-618a-46a2-a216-180577e829ac%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVqvNh8RKQPS%2BHYKBu4YK8nHnh0mMWMxNNRBF28%3DNMbBJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't update extended user django model

2015-07-21 Thread Sadaf Noor
Did you "python manage.py migrate"?


2015-07-21 15:07 GMT+06:00 Info Test :

> Any error appear on console, is it possible that only superuser can do
> that?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8e3bd42d-da1c-42a1-be11-296c2d49d208%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8e3bd42d-da1c-42a1-be11-296c2d49d208%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVoGbXqVCXTtc1DbUKm0tRkoJ6MKxu%2BvAmSGsFmJT03LgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Thumbnails In Django

2015-07-21 Thread Sadaf Noor
In one of my projects I used sorl (
https://github.com/mariocesar/sorl-thumbnail) instead, it was super easy
and best fit for my project. Every time it asks for a new thumbnail BUT if
it exists in its cache, then that one is returned. If it doesn't, a new one
is generated and stored, then returned. So ultimately it saves. I don't
know your use case. I am just saying it can be an option.

2015-07-22 1:22 GMT+06:00 divyanshi kathuria :

> I am using Django Rest framework. I have three fields in my Pin Model :
> image,thumbnail_medium and thumbnail_small. I want to create two thumbnails
> from the image. How to do that? I tried the following code : But it's not
> working.
> from django.db import models
> from django.contrib.auth.models import User
> from thumbs import ImageWithThumbsField
> #from taggit.managers import TaggableManager
> from PIL import Image
> from cStringIO import StringIO
> from django.core.files.uploadedfile import SimpleUploadedFile
> import os
>
>
> class Pin(models.Model):
>
> url = models.SlugField(blank=True, null=True)
> title = models.TextField(blank=False,null=False,default='Untitled')
> description = models.TextField(blank=True, null=True)
> is_pro = models.BooleanField(default=False)
> is_hidden = models.BooleanField(default=False)
> is_for_sale = models.BooleanField(default=False)
> is_pro = models.BooleanField(default=False)
> price = models.DecimalField(blank=True, null=True, max_digits=10,
> decimal_places=2 ,default=0)
> price_in_rs = models.BooleanField(default=False)
> size_in_inches = models.BooleanField(default=True)
> medium = models.TextField(blank=True, null=True)
> length = models.DecimalField(blank=True, null=True, max_digits=10,
> decimal_places=2 ,default=0)
> width = models.DecimalField(blank=True, null=True, max_digits=10,
> decimal_places=2 ,default=0)
> hearts = models.IntegerField(blank=True, null=True, default=0)
> image = models.ImageField(upload_to='pins/pin/originals/')
> thumbnail = models.ImageField(upload_to='pins/pin/thumbnails/')
> published = models.DateTimeField(auto_now_add=True)
> #tags = TaggableManager()
>
> def __unicode__(self):
> return self.url
>
> def save(self):
> from PIL import Image
> from cStringIO import StringIO
> from django.core.files.uploadedfile import SimpleUploadedFile
>
> # Set our max thumbnail size in a tuple (max width, max height)
> THUMBNAIL_SIZE = (50, 50)
>
> # Open original photo which we want to thumbnail using PIL's Image
> # object
> image = Image.open(self.image.name)
>
> # Convert to RGB if necessary
> # Thanks to Limodou on DjangoSnippets.org
> # http://www.djangosnippets.org/snippets/20/
> if image.mode not in ('L', 'RGB'):
> image = image.convert('RGB')
>
> # We use our PIL Image object to create the thumbnail, which
> already
> # has a thumbnail() convenience method that contrains proportions.
> # Additionally, we use Image.ANTIALIAS to make the image look
> better.
> # Without antialiasing the image pattern artifacts may result.
> image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)
>
> # Save the thumbnail
> temp_handle = StringIO()
> image.save(temp_handle, 'png')
> temp_handle.seek(0)
>
> # Save to the thumbnail field
> suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
> temp_handle.read(), content_type='image/png')
> self.thumbnail.save(suf.name+'.png', suf, save=False)
>
> # Save this photo instance
> super(Pin, self).save()
>
> Can anyone figure out the problem here? Why is it not creating thumbnails?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/13e46569-3641-438d-9201-fa079f7f89b2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/13e46569-3641-438d-9201-fa079f7f89b2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
  Md. Sadaf Noor (@sadaf2605 <https:/

Question regarding making urls aliases

2018-03-27 Thread Sadaf Noor
I am using django rest framework filters in my app. For a viewset that 
looks like following:


|classProductViewSet(viewsets.ModelViewSet):queryset 
=Product.objects.all()serializer_class =ProductSerializerlookup_field 
='slug'filter_backends =(SearchFilter,DjangoFilterBackend,)filter_fields 
=('category__slug','brand__slug')|


It adds following url:

|http://*.compute.amazonaws.com:8000/product/?category__slug=smart-phone&brand__slug=asus&;|

I want to keep using|DjangoFilterBackend|as I am using, but I want the 
api to look like following:


|http://*.compute.amazonaws.com:8000/categories/smart-phone/brands/asus|

I know that I can use RedirectViews but I don't want to redirect user. 
Can I somehow make alias urls without using nginx or other reverse proxy 
tools?



Sadaf Noor (@sadaf2605 <http://twitter.com/sadaf2605>)
http://blog.sadafnoor.com

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b477ba0d-e6fc-078e-2f48-863195578a93%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Integrating RabbitMQ with Django

2015-09-16 Thread Sadaf Noor
Instead you can try using celery. For demonstration purpose I have tried an
image processing app using rabbitmq, celery with flask. It worked great. It
can be found at my blog (
http://www.sadafnoor.com/blog/rabbitmq-celery-demonstration-using-image-processing-app-on-flask/
).
On 16-Sep-2015 6:53 PM, "Erol Merdanović"  wrote:

> Hi all
>
> I'm using Django to develop a service. Service connects to RabbitMQ and
> receives events that are translated to creating/updating/deleting of the
> database records.
>
> What is the best way to run RabbitMQ consumer with Django? I'm using Pika
> library and I run consumer as a management command (python manage.py
> listen_to_changes). Is this a good solution? I don't see it so. I'm running
> Django as WSGI so I presume there are no start/stop Django events that I
> could plugin in to start/stop consumer.
>
> I'm aware of the Celery and how it nicely integrates into Django, but for
> me it's not an option.
>
> What do you suggest? How to run RabbitMQ with Django (stability is the
> main objective).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e2b0cfd3-f33f-485c-9497-98fd281c9cd2%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVqY3PEkPauv%2BCsMZE1xofmkj%2BYcMJkWkfmvkdNbp_janQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


how to design app structure

2015-09-27 Thread Sadaf Noor

Hello,
My question is regarding design pattern of django app. what is the 
philosophy behind apps in django? when should we decide to split our web 
app into many django apps? If you could share you relevant experiences, 
it would be helpful.



--
 Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
www.sadafnoor.com <http://www.sadafnoor.com>

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5608B3E9.7040509%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


My django model joining wrong fields when there are multiple related fields with join

2018-09-19 Thread Sadaf Noor
My product model has two different relationship with category model:

   1. One to One
   2. One to Many through ProductShadowCategory table.

Now the situation is when I tried to fetch using the second relationship, I
am getting the result from my first relationship.

For example this is what I am trying to print:

Category.objects.get(slug="root").shadow_products.all()

but it converts to following sql :

print(Category.objects.get(slug="root").shadow_products.all().query)

SELECT `product_management_product`.`id`,
`product_management_product`.`slug`,
`product_management_product`.`category_id`,
`product_management_product`.`brand_id` FROM
`product_management_product` WHERE
`product_management_product`.`category_id` = 720

My models looks like following:

class Category(SlugableModel):
#...
shadow_products =
models.ManyToManyField("product_management.Product",
through="product_management.ProductShadowCategory")
class Product(SlugableModel):
#...
category = models.ForeignKey(Category,on_delete=models.CASCADE,
related_name="products", validators=[leaf_category])
class ProductShadowCategory(MyModel):
category = models.ForeignKey(Category,on_delete=models.CASCADE)
product = models.ForeignKey(Product,on_delete=models.CASCADE)

class Meta:
unique_together = ('category', 'product')

Also asked on stackoverflow:
https://stackoverflow.com/questions/52417494/my-django-model-joining-wrong-fields-when-there-are-multiple-related-fields-with
-- 




 Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.me <https://www.w3schools.com/tags/www.sadafnoor.me>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAJ2eVqy6%3DAynOrG1peGVpcTg2H9xw2v%2BjLRavz%2BDnjcZWFCYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.