Re: Result of queryset in Django 1.10 is not sorted

2017-09-05 Thread Antonis Christofides
Hi,

if you don't specifically ask for the query results to be sorted, their order
will be undefined. Differences in your Django version or the RDBMS version or
the OS or the environment or anything may result in a different sort order. If
you want the query to be sorted, you must either use the ordering meta option
 or the
order_by method
.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-09-05 09:10, Priyanka Thakur wrote:
> Hi,
>
> As part of migration to Django 1.10.4 from 1.7, I have noticed that queryset
> results are unsorted, compared to previous version. 
>
> Has same behaviour been observed by anyone?
>
> Regards,
> Priyanka
> -- 
> 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/777067c4-7a66-416d-8c5f-576566d6b4c1%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c58b7566-1834-6d3c-0842-1e67baa10335%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to add more fields to each ManyToMany Field in Django?

2017-09-05 Thread Omer Iqbal
Hey, Thanks for replying. I tried what you said but It's still giving 
the error. I've also updated the StackOverflow question with updated code.
One more thing, as you said about JavaScript. I think I won't be needing it 
on that page because this *through *models seems to be the solution to my 
problem (once that table error is resolved). Because I think I can manually 
add "fees" through that additional field (by Choosing the university, and 
course from the drop down).




On Tuesday, September 5, 2017 at 3:03:14 AM UTC+5, mark wrote:
>
> I replied to your StackOverflow question. An error in your through model 
> caused the no such table error.
>
> Keep in mind that web pages are only generated once, and then presented to 
> the user. If you want the page to display the cost of the course based on 
> the university you pick on this page in the select box, then you need some 
> javascript to perform a real-time update to your admin page before to 
> display the correct price. There are frameworks available as django apps 
> for doing this.
>
> Mark
>
> On Mon, Sep 4, 2017 at 10:19 AM, Omer Iqbal  > wrote:
>
>> Hi,
>>
>>
>>
>>
>>
>>
>>
>> Is it possible to add one or more field (Char Field) to the options of 
>> ManyToMany field?
>>
>> My current models result in this:
>>
>> 
>>
>>
>>
>> *My Models:*
>>
>>
>> class engineeringUni(models.Model):
>>
>>
>> field2 = models.CharField(max_length=200)
>> des_eng = models.CharField(max_length=1000, default='Add description'
>> )
>>
>>
>> def __str__(self):
>>
>> return self.field2
>>
>>
>> def description_eng_universities(self):
>>
>> return self.des_eng
>>
>>
>>
>>
>> class engineering_courses(models.Model):
>>
>> course_name = models.CharField(max_length=400)
>>
>> course_description = models.CharField(max_length=1000, default='This 
>> is a description')
>>
>> course_offered_by = models.ManyToManyField(engineeringUni, 
>> related_name='course_offered_by')
>>
>> course_duration = models.IntegerField(blank=False, default='2')
>>
>>
>>
>>
>> def __str__(self):
>>
>> return self.course_name
>>
>>
>>
>>
>> def description_course(self):
>>
>> return self.course_description
>>
>>
>>
>>
>> def offered_by_courses(self):
>>
>> return self.course_offered_by
>>
>>
>>
>>
>> def duration_courses(self):
>>
>>
>>
>> return str(self.course_duration)
>>
>>
>>
>> As you can see in the image, I have the options in the ManyToMany field. 
>> Those options are:
>>
>>
>>- University 1
>>- University 2
>>- University 3
>>
>>
>>
>> What I want to have is an additional text (Char) field next to each of 
>> these options (University 1, University 2, University 3).
>>
>> Is this possible?
>>
>>
>> I asked this question on StackOverflow (link 
>> )
>>  
>> and through one answer, I became aware of *through* models in ManyToMany 
>> field and on using through models, I get *no such table error*.
>>
>>
>> You might be asking why do I need this? As you can see in the image, my 
>> project (personal project) is about universities etc. What I want is that 
>> If I add a course and then choose a university (from ManyToMany Field), I 
>> should have an option to enter the fees of that course for that particular 
>> university.
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/f9efd14f-3d82-4032-a425-48d3b0dfaede%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1460ea3c-330a-4a30-b7c1-a34bdc169473%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Result of queryset in Django 1.10 is not sorted

2017-09-05 Thread Jani Tiainen

Hi,

Unless you have applied ordering, either in model Meta, or in your query 
clause, results are really "in no particular order". Most of the 
databases do return results in order the data is read from the disk, but 
that's not quaranteed.


If you require ordering, add .order_by() to your query to guarantee 
wanted sorting.



On 5.9.2017 9.10, Priyanka Thakur wrote:

Hi,

As part of migration to Django 1.10.4 from 1.7, I have noticed that 
queryset results are unsorted, compared to previous version.


Has same behaviour been observed by anyone?

Regards,
Priyanka
--
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/777067c4-7a66-416d-8c5f-576566d6b4c1%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ecea4a6d-5c89-36fd-1092-1b2ca5c678d3%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


APIView or ListAPIView,RetrieveAPIView while developing a restful application

2017-09-05 Thread Rakhee Menon

I am developing a restful application with angular technology as front end 
and django at the back end..Please can anyone suggest which type of views 
should I use,Should I go for APIVIEW or separate views like 
ListAPIView,RetrieveAPIView or in any case go for viewset

-- 
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/5d50b701-5936-4021-a19b-3ee0287477db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


APIView or ListAPIView,RetrieveAPIView while developing a restful application.

2017-09-05 Thread Rakhee Menon

​I am developing a restful application with angular technology as front end 
and django at the back end..Please suggest which type of views should I 
use,Should 
I go for APIVIEW or separate views like ListAPIView,RetrieveAPIView or in 
any case go for viewset​??

-- 
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/dd1f4821-c9eb-4512-810f-e711c17c25d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Dynamic model, reverse foreign key not working

2017-09-05 Thread Roman Akopov
Hello,

My problem is very rare so I'll try ad add as much useful detail as 
possible.

I am using python 3.5 and 3.6, Django 1.11.4 

I am creating complex security related application and need to generate 
additional models based on other applications' models. In general, 
everything works fine, models are created, migrated without a problem. But 
there is single problem I totally failed to solve.

Let's say there is preexisting model Alpha of some other application and I 
dynamically create model Beta which references Alpha with ForeignKey. The 
problem is that Beta does not get reverse relation, so I can query for 
beta.alpha, but not for alpha.betas. I receive 
"django.core.exceptions.FieldError: Cannot resolve keyword 'betas' into 
field. Choices are: x, y, z"

Here is my code























*def _create_dynamic_model(self, model_label, fields, attributes=None, 
options=None):from django.db import modelsclass 
Meta:passsetattr(Meta, 'app_label', '_talos')if 
options is not None:for key, value in 
options.items():setattr(Meta, key, value)attrs = 
{'__module__': '_talos', '_talos_dynamic': True, 'Meta': Meta}if 
attributes:attrs.update(attributes)if 
fields:attrs.update(fields)model = type(model_label, 
(models.Model,), attrs)return model*

I call it like this (where self.model is referenced model class)

def _create_object_permission_model(self):
from django.db import models

return self._create_dynamic_model(
'o_{0}_{1}'.format(self.model._meta.app_config.label, 
self.model.__name__),
fields={
'role': models.ForeignKey(
'talos.Role',
related_name='+',
on_delete=models.CASCADE),
'permission': models.ForeignKey(
'talos.ObjectPermission',
related_name='+',
on_delete=models.CASCADE),
'target': models.ForeignKey(
self.model,
related_name='talos_permissions', # self.model does not 
receive reverse relation!
on_delete=models.CASCADE)
},
options={
'unique_together': [('role', 'permission', 'target')],
'index_together': [
('target', 'permission', 'role'),
('target', 'role', 'permission'),
('role', 'target', 'permission')]
})


I tried calling contribute_to_class and contribute_to_related_class methods 
manually, tried to call this code at different moments (My application 
ready method, class_prepared signal handler), with absolutely no luck.

I tried to read Django sources, and got that contribute_to_related_class is 
called from contribute_to_class with delay, but it did not help me realize 
what exactly I am doing wrong.

I am trying to use reverse relation from custom view and admin, so 
everything should be pretty much initialized already.

Roman

-- 
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/762bd583-1daa-4229-8355-21c9fc821986%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to add more fields to each ManyToMany Field in Django?

2017-09-05 Thread Omer Iqbal
Thank you - The problem is solved. 
I had deleted the migration files because It was showing no table error. 
But on deleting the database file (db.sqlite3) and re-applying migrations, 
It worked.

-- 
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/f52b7db5-c7b9-4ac3-bc58-ba5688ab212d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model, reverse foreign key not working

2017-09-05 Thread Michal Petrucha
On Tue, Sep 05, 2017 at 03:47:37AM -0700, Roman Akopov wrote:
> Hello,
> 
> My problem is very rare so I'll try ad add as much useful detail as 
> possible.
> 
> I am using python 3.5 and 3.6, Django 1.11.4 
> 
> I am creating complex security related application and need to generate 
> additional models based on other applications' models. In general, 
> everything works fine, models are created, migrated without a problem. But 
> there is single problem I totally failed to solve.
> 
> Let's say there is preexisting model Alpha of some other application and I 
> dynamically create model Beta which references Alpha with ForeignKey. The 
> problem is that Beta does not get reverse relation, so I can query for 
> beta.alpha, but not for alpha.betas. I receive 
> "django.core.exceptions.FieldError: Cannot resolve keyword 'betas' into 
> field. Choices are: x, y, z"

So the deal is that each model's _meta caches a bunch of structures
storing the list of fields, reverse relations, and so on, the first
time you access any of them. If you add a new field (or a new reverse
relation) after those caches have already been filled, the new field
or relation won't be reflected in them, leading to errors just like
yours.

There's an internal undocumented API that takes care of this,
Model._meta._expire_cache(), which will clear all those caches. It
should do the trick for you, but as always with private APIs, be aware
that it might break or change in the future.

Cheers,

Michal

-- 
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/20170905113641.GK8762%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Dynamic model, reverse foreign key not working

2017-09-05 Thread Roman Akopov


On Tuesday, September 5, 2017 at 3:38:17 PM UTC+4, Michal Petrucha wrote:
>
> On Tue, Sep 05, 2017 at 03:47:37AM -0700, Roman Akopov wrote: 
>
> So the deal is that each model's _meta caches a bunch of structures 
> storing the list of fields, reverse relations, and so on, the first 
> time you access any of them. If you add a new field (or a new reverse 
> relation) after those caches have already been filled, the new field 
> or relation won't be reflected in them, leading to errors just like 
> yours. 
>
> There's an internal undocumented API that takes care of this, 
> Model._meta._expire_cache(), which will clear all those caches. It 
> should do the trick for you, but as always with private APIs, be aware 
> that it might break or change in the future. 
>
> Cheers, 
>
> Michal 
>


Michael,

Thanks for great hint!

Unfortulately, it did not help. I have added "model._meta._expire_cache()" 
call almost everywhere, before generating dynamic model, after, between 
steps, it did not help a bit, error is exactly the same.
Also, I have additionally tested my application against django 1.10 and 
django 1.9 and got exactly the same result.

Roman

-- 
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/e60febee-ab7e-4bbe-a637-6a4302f835bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model, reverse foreign key not working

2017-09-05 Thread Michal Petrucha
On Tue, Sep 05, 2017 at 04:56:10AM -0700, Roman Akopov wrote:
> Unfortulately, it did not help. I have added "model._meta._expire_cache()" 
> call almost everywhere, before generating dynamic model, after, between 
> steps, it did not help a bit, error is exactly the same.
> Also, I have additionally tested my application against django 1.10 and 
> django 1.9 and got exactly the same result.

On which models did you call that? You should call it on the target
model of any relationship that you create dynamically. So if you have
existing models Target1, and Target2, and create a new model Dynamic
with a ForeignKey(Target1) and ManyToManyField(Target2), you'd need to
call _expire_cache() on Target1 and Target2 right after creating the
dynamic model, but before trying to make any queries using those new
reverse relations.

If this doesn't help, then you might have to investigate if there's
perhaps some cached attribute that doesn't get cleared.

Good luck,

Michal

-- 
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/20170905123820.GL8762%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread Rakhee Menon
CODE:

class FormList(APIView):
def get(self, request, id):
import ipdb;ipdb.set_trace()
item_obj = ItemMaster.objects.get(id=id)
serializer = ItemMasterSerializer(forms,many=False)
return Response(serializer.data, content_type="application/json")
def get(self,request):
forms = ItemMaster.objects.all()
serializer=ItemMasterSerializer(forms,many=True)
return Response(serializer.data, content_type="application/json") 



I get this error.django-got-an-unexpected-keyword-argument-id. 
when i try to access a specific item..Please can anyone suggest how to 
solve this bug using APIViews and not by using viewset  as there is lot of 
customization in my API.

-- 
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/8f1a1edf-ed7f-490f-8c29-73aa31531a3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


error while creating superuser

2017-09-05 Thread Sandeep S
Hi All,

I am getting error when I tried to create a superuser. I am using Cassandra 
3.0 with Django  1.11.4. 

I used this command in Pycharm: manage.py createsuperuser

error: "cassandra.protocol.SyntaxException: 
"

What am I doing wrong?

-- 
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/1878d9c4-88e9-4182-9c83-6b50b80fb4ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model, reverse foreign key not working

2017-09-05 Thread Roman Akopov
I call it on target model, the one with reverse relation missing.

On Tuesday, September 5, 2017 at 4:40:02 PM UTC+4, Michal Petrucha wrote:
>
> On Tue, Sep 05, 2017 at 04:56:10AM -0700, Roman Akopov wrote: 
> > Unfortulately, it did not help. I have added 
> "model._meta._expire_cache()" 
> > call almost everywhere, before generating dynamic model, after, between 
> > steps, it did not help a bit, error is exactly the same. 
> > Also, I have additionally tested my application against django 1.10 and 
> > django 1.9 and got exactly the same result. 
>
> On which models did you call that? You should call it on the target 
> model of any relationship that you create dynamically. So if you have 
> existing models Target1, and Target2, and create a new model Dynamic 
> with a ForeignKey(Target1) and ManyToManyField(Target2), you'd need to 
> call _expire_cache() on Target1 and Target2 right after creating the 
> dynamic model, but before trying to make any queries using those new 
> reverse relations. 
>
> If this doesn't help, then you might have to investigate if there's 
> perhaps some cached attribute that doesn't get cleared. 
>
> Good luck, 
>
> Michal 
>

-- 
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/9e7aa61d-23e0-498c-83e2-500f39941351%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread Vijay Khemlani
To retrieve a particular object in your API you should implement it in a
method called "retrieve", not "get", if I remember correctly

On Tue, Sep 5, 2017 at 10:28 AM, Rakhee Menon 
wrote:

> CODE:
>
> class FormList(APIView):
> def get(self, request, id):
> import ipdb;ipdb.set_trace()
> item_obj = ItemMaster.objects.get(id=id)
> serializer = ItemMasterSerializer(forms,many=False)
> return Response(serializer.data, content_type="application/json")
> def get(self,request):
> forms = ItemMaster.objects.all()
> serializer=ItemMasterSerializer(forms,many=True)
> return Response(serializer.data, content_type="application/json")
>
>
>
> I get this error.django-got-an-unexpected-keyword-argument-id.
> when i try to access a specific item..Please can anyone suggest how to
> solve this bug using APIViews and not by using viewset  as there is lot of
> customization in my API.
>
> --
> 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/8f1a1edf-ed7f-490f-8c29-73aa31531a3b%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3fp0uWeBr0a6ycGvw03ZKqzXRdepJpD%2B34VKxTQV-4hQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic model, reverse foreign key not working

2017-09-05 Thread Roman Akopov
I have investigated a bit more and looks lite it is Options._relation_tree 
property, it's value is calculated by _populate_directed_relation_graph 
only once and it is @cached_property, so I see no valid way to reset value

On Tuesday, September 5, 2017 at 4:40:02 PM UTC+4, Michal Petrucha wrote:
>
>
> If this doesn't help, then you might have to investigate if there's 
> perhaps some cached attribute that doesn't get cleared. 
>
> Good luck, 
>
> Michal 
>

-- 
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/0965a000-127a-4ad1-a4f1-46dd7e805d16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django security releases issued: 1.11.5 and 1.10.8

2017-09-05 Thread Tim Graham
Today the Django team issued 1.11.5 and 1.10.8 as part of our security 
process. These releases address a security issue, and we encourage all 
users to upgrade as soon as possible:

https://www.djangoproject.com/weblog/2017/sep/05/security-releases/

As a reminder, we ask that potential security issues be reported via 
private email to secur...@djangoproject.com and not via Django's Trac 
instance or the django-developers list. Please see 
https://www.djangoproject.com/security for further information.

-- 
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/da74bef7-e0dc-4fff-a44e-8fd51bc2d012%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Displaying a photo from a database

2017-09-05 Thread ron_w_add via Django users
 

Hello

 

I have this photo:

 

wildlifephotos/2017/07/26/2017-06-30_Lansdowne_-_Syrphus_Sp_A_01.JPG

in the project’s following folder

 

mysite/media

as per the following (simplified) tree

 
C:.
|   
\---mysite 
|   db.sqlite3 
|   manage.py 
|   
+---media 
|   |   
|   \---wildlifephotos 
|   |   2017-04-29_-_11_Lansdowne_-_Moth_A_02.JPG 
|   |   
|   \---2017 
|   \---07 
|   \---26 
|   2017-06-30_Lansdowne_-_Syrphus_Sp_A_01.JPG 
|   
+---mysite 
|   settings.py 
|   tests.py 
|   urls.py 
|   wsgi.py 
|   __init__.py 
|   
\---wlp_app 
|   admin.py 
|   apps.py 
|   models.py 
|   tests_apps.py 
|   tests_urls.py 
|   tests_views.py 
|   urls.py 
|   views.py 
|   
+---static 
|   \---wlp_app 
|   +---img 
|  fred.JPG 
|  Grandad.JPG 
|  
|
+---templates 
\---wlp_app 
base.html 
index.html 
photo.html




It is in the ‘photo_taken’ field of the ‘Photo’ table shown in the model.py 
shown below.

 
class Photo(models.Model):

 name = models.CharField(max_length=50) 
 description = models.TextField() 
 location = models.ForeignKey(Location) 
 height_field = models.IntegerField(default=0) 
 width_field = models.IntegerField(default=0) 
 photo_taken = models.ImageField(upload_to='wildlifephotos/%Y/%m/%d', 
 null=True, blank=True, 
 width_field="width_field", height_field="height_field")


 

I am wanting to display the photo in the following 'personal/header.html’ 
file within the ‘block content’ to ‘endblock’:

 
 
 
  
{% block content %} 
{% endblock %} 
  
 


 

…where this block content is in my ‘photo.html’ file as shown here:

 
{% extends 'personal/header.html' %}

{% block content %} 
  
 < Back 
 {% if pht != None %} 
   {{ pht.name }} 
   {{ pht.location.name }} 
   {{ pht.description }} 
   {{ pht.photo_taken }} 
   {% else %} 
   Invalid item ID 
 {% endif %} 
{% endblock %}


 

When I run the above I get the following text on the web page and is what I 
expect:

 
Hoverfly
Lansdowne 
Syrphus is a genus of hoverflies 
wildlifephotos/2017/07/26/2017-06-30_Lansdowne_-_Syrphus_Sp_A_01.JPG


 

However, when I try to add the photo to the page I’m getting stuck. If I 
try adding ‘ 
 < Back 
 {% if pht != None %} 
   {{ pht.name }} 
   {{ pht.location.name }} 
   {{ pht.description }} 
   {{ pht.photo_taken }} 

   {% else %} 
   Invalid item ID 
 {% endif %} 
{% endblock %}


…I get the following message (curly brackets and enclosed text were 
highlighted in red):
Could not parse the remainder: ' 'pht.photo_taken.name'' from 'MEDIA_URL '
pht.photo_taken.name''

28 


I’ve used MEDIA_URL since this refers to the media folder in the settings.py

 
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 
MEDIA_URL = '/media/'


 

I’ve also used the following:

 

 
  

…which led to the following error message (curly brackets and enclosed text 
were highlighted in red):

 
Invalid block tag on line 28: 'MEDIA_URL', expected 'elif', 'else' or 
'endif'. Did you forget to register or load this tag?

28 


 

Changing MEDIA_URL in the above to MEDIA_ROOT gave the same error message 
and changing the ‘%’ to curly braces gave the earlier ‘Could not parse the 
remainder…’ message.

 

I’m clearly missing one or two important steps but cannot seen them. Can 
anyone advise me on what I am doing wrong, please? 

 

Thanks

 

Ron

-- 
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/bef2a451-f504-4fad-bcad-a9ebef8fa9e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Displaying a photo from a database

2017-09-05 Thread James Schneider
>
> However, when I try to add the photo to the page I’m getting stuck. If I
> try adding ‘
>
> {% block content %}
>  
>  < Back
>  {% if pht != None %}
>{{ pht.name }}
>{{ pht.location.name }}
>{{ pht.description }}
>{{ pht.photo_taken }}
> "responsive-img" style='max-height:100px;' alt="face">
>{% else %}
>Invalid item ID
>  {% endif %}
> {% endblock %}
>
>
> …I get the following message (curly brackets and enclosed text were
> highlighted in red):
> Could not parse the remainder: ' 'pht.photo_taken.name'' from 'MEDIA_URL '
> pht.photo_taken.name''
>
> 28  style='max-height:100px;' alt="face">
>



Note that {{ MEDIA_URL }} is strictly a variable reference and takes no
other inputs. You are treating it as a template tag, which are enclosed
using {% %}, hence the reason you are receiving this error.



>
>
> I’m clearly missing one or two important steps but cannot seen them. Can
> anyone advise me on what I am doing wrong, please?
>
>
>
> Thanks
>
>
>
> Ron
>

What you likely want is this:



(Note that the src= has " surrounding both variables, and that I'm using
pht.photo_taken.url rather than pht.photo_taken.name, which should only be
used to reference the actual file on disk per the docs.)

https://docs.djangoproject.com/en/1.11/ref/models/fields/#imagefield
https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.FileField.storage

Which should render to something like this:



I don't even think you need MEDIA_URL in your templates given the .url
shortcut provided by the ImageField model field. That's probably why
MEDIA_URL is not made available in the template by default:

https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-MEDIA_URL

-James

-- 
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/CA%2Be%2BciXkBYG9eq%2BsmBiVmyHXCtGfLGxcydMByc739ZcW2SuHHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: error while creating superuser

2017-09-05 Thread James Schneider
On Tue, Sep 5, 2017 at 5:42 AM, Sandeep S  wrote:

> Hi All,
>
> I am getting error when I tried to create a superuser. I am using
> Cassandra 3.0 with Django  1.11.4.
>
> I used this command in Pycharm: manage.py createsuperuser
>
> error: "cassandra.protocol.SyntaxException:  [Syntax error in CQL query] message="line 1:260 no viable alternative at
> input '.' (
> ...auth_user.date_joined FROM auth_user WHERE [auth_user])">
> "
>
> What am I doing wrong?
>
>

Note that Cassandra is not a supported DB platform for use with Django. I'm
assuming you are using a 3rd party connector and DB driver like
django-cassandra-engine.

Given that the default django.contrib.auth models (needed to create users)
do not inherit from the parent DjangoCassandraModel included in the app,
I'm guessing that your django.contrib.auth models are not available in the
DB, hence the SQL error.

You may be able to work around this by creating a custom user model that
inherits from DjangoCassandraModel, but YMMV.

I would also pose the question to the 3rd party author who already has a
section on management commands. It would be worth them adding it to their
documentation.

-James

-- 
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/CA%2Be%2BciXfFq3Sr_gH_QdRnvicH_6p-MkhvFS1iStdbOQn4O1AFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using data migration to create initial users errors

2017-09-05 Thread Tim Huang
My instinct tells me that there may be something wrong with the classmethod 
normalize_username in _create_user method. 

What Matias suggested works. 

-- 
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/6a37ad93-42b1-4595-9839-72148f42829f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread Rakhee Menon


On Tuesday, September 5, 2017 at 8:06:09 PM UTC+5:30, Vijay Khemlani wrote:
>
> To retrieve a particular object in your API you should implement it in a 
> method called "retrieve", not "get", if I remember correctly
>
> On Tue, Sep 5, 2017 at 10:28 AM, Rakhee Menon  > wrote:
>
>> CODE:
>>
>> class FormList(APIView):
>> def get(self, request, id):
>> import ipdb;ipdb.set_trace()
>> item_obj = ItemMaster.objects.get(id=id)
>> serializer = ItemMasterSerializer(forms,many=False)
>> return Response(serializer.data, content_type="application/json")
>> def get(self,request):
>> forms = ItemMaster.objects.all()
>> serializer=ItemMasterSerializer(forms,many=True)
>> return Response(serializer.data, content_type="application/json") 
>>
>>
>>
>> I get this error.django-got-an-unexpected-keyword-argument-id. 
>> when i try to access a specific item..Please can anyone suggest how to 
>> solve this bug using APIViews and not by using viewset  as there is lot of 
>> customization in my API.
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/8f1a1edf-ed7f-490f-8c29-73aa31531a3b%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d658fd4d-2056-4c4f-bb28-0b10964c39a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread Rakhee Menon

>
> But while using APIView there is no retrieve method.We have only 
>> get,post,delete and put methods.
>>
> As there is lot of customization in my API i need to use APIViews only... 
> So please tell me how to access specific items using APIViews
>

-- 
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/ddab44ca-7d03-4e8a-9424-e406cdd27b42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using data migration to create initial users errors

2017-09-05 Thread Melvyn Sopacua
This is an old thread about 1.7.
Things have improved since then:
https://docs.djangoproject.com/en/1.11/topics/migrations/#model-managers

On Wed, Sep 6, 2017 at 4:01 AM, Tim Huang  wrote:
> My instinct tells me that there may be something wrong with the classmethod
> normalize_username in _create_user method.
>
> What Matias suggested works.
>
> --
> 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/6a37ad93-42b1-4595-9839-72148f42829f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Melvyn Sopacua

-- 
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/CA%2Bgw1GXdn7dgnBF4CuB4iPtfwjCR8xBc4aOqgdZPW3MkOtJv8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread James Schneider
On Sep 5, 2017 6:28 AM, "Rakhee Menon"  wrote:

CODE:

class FormList(APIView):
def get(self, request, id):
import ipdb;ipdb.set_trace()
item_obj = ItemMaster.objects.get(id=id)
serializer = ItemMasterSerializer(forms,many=False)
return Response(serializer.data, content_type="application/json")
def get(self,request):
forms = ItemMaster.objects.all()
serializer=ItemMasterSerializer(forms,many=True)
return Response(serializer.data, content_type="application/json")



I get this error.django-got-an-unexpected-keyword-argument-id.
when i try to access a specific item..Please can anyone suggest how to
solve this bug using APIViews and not by using viewset  as there is lot of
customization in my API.


The issue arises because you are defining the get() method twice with
different signatures. The second definition of get() without the id
argument is the 'active' definition since it is defined last, and had no
idea what to do with the extra 'id' argument.

Python does not support function/method overloading like Java, because of
PEP 8 and keep it simple and DRY and everything else about the Python
philosophy. It also ultimately names for cleaner and more legible code.

Not sure what you mean by a lot of customization. This code is pretty
boiler plate and would be better served by using a generic viewset in DRF,
such as ReadOnlyModelViewset:

http://www.django-rest-framework.org/api-guide/viewsets/#readonlymodelviewset

-James

-- 
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/CA%2Be%2BciVCgC6vvzCvRxGuMoTzq7FW051WP5oSUAKdwD%3D%3DE66BqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread Rakhee Menon
Customization in the sense..I have lot of calculations to do so its not 
possible using viewset.

-- 
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/1b4a5c0d-b409-4dbd-949a-8752fa5caacd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread James Schneider
On Sep 5, 2017 11:21 PM, "Rakhee Menon"  wrote:

Customization in the sense..I have lot of calculations to do so its not
possible using viewset.


Ah, that isn't reflected in the example code you provided. Fair enough.

Custom logic like calculations can be integrated in to any view or viewset.
Often times the logic is broken out in to separate standalone functions and
called by some simple overrides on the view[set].

You can do everything with an APIView if you'd like, but you may be signing
up for more work than necessary. If you have your heart set on APIView for
whatever reason, you can tweak your code by combining your two get()
definitions in to one:

from django.shortcuts import get_object_or_404

class FormList(APIView):
def get(self, request, id=None):
if id:
obj_data = get_object_or_404(ItemMaster, id=id)
many = False
else:
obj_data = ItemMaster.objects.all()
many = True

serializer = ItemMasterSerializer(obj_data, many=many)

return Response(serializer.data, content_type="application/json")


Admittedly I haven't dealt with DRF serializers in a while, but I believe
that will work. YMMV.

-James

-- 
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/CA%2Be%2BciXu0XTa5r0uLedv4SAMDsp_S%3DhUHg7Vpxp7z3xhDxWqKQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to write APIview to access a specific item by using APIViews only

2017-09-05 Thread James Schneider
>
>
> Custom logic like calculations can be integrated in to any view or
> viewset. Often times the logic is broken out in to separate standalone
> functions and called by some simple overrides on the view[set].
>

I forgot to mention, you may want to integrate that business logic directly
in to your models if the logic will be accessed from more than one view,
rather than trying to crowbar in the same operation to multiple views.
Model managers work well for logic that is applied across groups of model
instances (ie filtering specific instances out, or performing calculations
based on a set of criteria against a model type), and methods defined
directly on the model should work specifically with that model instance
without the need for a crazy view.

Typically very little business logic is integrated in to the views (which
is why so much work has gone in to making them generic, they are often
boiler-plate with minute differences such as the template to render or the
class of model to query).

-James

-- 
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/CA%2Be%2BciXZ0Et2pFWQUUkC-7eLqQTGi-tmjH7iSAiq28UCNOjGrw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.