Re: How to develop a frontend web app for using REST services

2015-10-18 Thread kk



On Sunday 18 October 2015 06:51 PM, bobhaugen wrote:

krmane, are you posting these same questions in the REST framework forum?

I'm guessing they would like a SQLAlchemy plugin.

If such a plugin does exist it is great.


Unlike you, however, I like their documentation, and have found the 
DRF gang to be responsive to issues.  That being said, I haven't 
actually used it in production yet. Just experimenting.
I too don't find the documentation bad or unorganized, just that there 
are some situations not covered.
And I feel enough time should have been given to explain fundamentals of 
serializers or viewsets.
For example no matter which ORM I use, I do not totally rely on the 
Object mapping in any big project.
The approach I take is to use ORM for small result sets and using 
sqlalchemy expression language for big tasks.
Data objects have an overhead and the convenience comes at a cost of 
speed for huge data such as those with more than 5 records and that 
too when queries are complex enough.

Of course I will write to them in a short while.
happy hacking.
Krishnakant.

On Saturday, October 17, 2015 at 9:28:33 AM UTC-5, krmane wrote:

Hi again,
Xavier, I have gone through the main DRF documentation and also
seen your blog.
I am wondering if you can send me an off line email which can
explain the relation between serializer and viewset?
I have not got the concept clear, I am beginner to REST and all I
understand is that the response is generally in form of json.
happy hacking.
Krishnakant.


On Friday 16 October 2015 03:39 PM, Xavier Ordoquy wrote:

Hi,

I wrote a short blog post about getting most of Django REST
framework without using Django models.

https://medium.com/@linovia/django-rest-framework-viewset-when-you-don-t-have-a-model-335a0490ba6f



You will loose the integration with the Django Models and will
need to do a few things by yourself (pagination for example) but
it’s still perfectly possible to do that.
Note that most of the documentation covers Django Models because
it’s where most of the options are. When you don’t use them, it’s
up to the developers to provide the content which will be very
different from a project to another.

Hope this will help,

Regards,
Xavier,
Linovia.



Le 16 oct. 2015 à 12:00, kk  a
écrit :

hello again,
I haven't got my doubts solved but a few got added.
I was again going through the tutorial on Django REST framework.
I am trying to know if I can use a serialiser without tying it
to the DJango ORM or for that matter without tying it to any thing?
I prefer using SQLAlchemy and get the data out using sql
expression language.
Then I would like to convert this data to json format for
sending as response.
Is this possible?
Happy hacking.
Krishnakant


On Friday 16 October 2015 11:39 AM, kk wrote:

Dear all.
I got some very important suggestions from members of this list
on using Django for an accounting and inventory system,
including Point of Sale.
After the POS topic was discussed,
OUr team decided to write a RESTfull server with all the
business logic in API.
We plan to do this using some thing like Flask micro framework
and then write a complete web app using Django to consume these
services.
Of course it could be argued that why not use Django REST
framework?
But here I am a bit surprised as well as a bit disappointed.
Contrary to what we have all seen and experienced about
Django's documentation, the rest framework is not at all
comprehensively documented.
I am still not totally understood the use of
|serializers.HyperlinkedModelSerializer. viewset is also not
totally explained properly. the tutorial is pretty fast and
confusing. I think a better example would have served it more
understandable. Or perhaps the documentation there asumed that
every one who reads it is a Django as well as REST expert, even
then it is confusing. Any ways coming back to the topic. So
What suggestions could I get about my main query? happy
hacking. Krishnakant. |

-- 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 http://groups.google.com/group/django-users
. To view this
discussion on the web visit
https://groups.google.com/d/msgid/django-users/5620CACC.2060702%40gmail.com

.
For more 

makemigrations and language_code

2015-10-18 Thread 'Hugo Osvaldo Barrera' via Django users
I'm having a rather confusing scenario regarding makemigrations and
language_code:

* I've an app (let's call it myapp) which I'm developing.
* myapp relies on the another app (let's call it libapp).
* myapp has language_code set to "es-ar".
* libapp was developed separately, and has been installed via pip.

While developing myapp, whenever I run "makemigrations" a migrations is
also created for libapp. The migrations updates all the verbose_name and
help_text fields and nothing else. I don't want this, especially since
it creates a conflict in the migration graph when I later upgrade
libapp.

How can I have makemigrations *ignore* the language_code?

Also, why does makemigrations create this migration for libapp, but not
an equivalent one for django.contrib.admin?
I tried looking at things like the admin to see how they avoid this, and
found no clues.

Thanks,

-- 
Hugo Osvaldo Barrera

-- 
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/1445230649.556626.413720273.7E8A1A88%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.


Re: Importing models from another app?

2015-10-18 Thread Luis Zárate
Is "mysite" in your python path?

2015-10-17 8:26 GMT-06:00 Gergely Polonkai :

> How does it fail, what is the error message? My first guess is that you
> should omit "mysite" from your import line, but without the exact message
> it's hard to tell.
>
> Best,
> Gergely
> On 17 Oct 2015 15:52, "svewa"  wrote:
>
>> Hello everyone,
>>
>> I have a question about the model interaction between different django
>> apps. In my project I have an app called *userprofile* containing my
>> *UserProfile* model. In another app I have an *Object* model, which of
>> course should have an owner. My idea is to give the *Object* class a
>> field:
>>
>> *owner = models.ForeignKey(Userprofile)*
>>
>> but the import:
>>
>> *from mysite.userprofile.models import UserProfile*
>>
>> *fails*
>>
>> --
>> 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/15ac9e1c-20a5-4a8c-a68b-6c05eefb6d78%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/CACczBUKQcDEtTJZXYkj5ySiujmnCCsgnxHh0hQ9j_GNHVHd-0A%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyNKGMqzwRTW5tLQCrjE%3DgNEShin-eZS4VLJmSmNaevY7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Lack of View permission in Django

2015-10-18 Thread Mike Dewhirst

On 19/10/2015 5:03 AM, Ankit Agrawal wrote:

I have an active Django project where the admin panel is used by the
customer support team. I have two questions -

1. Django lacks a `view` permission because of which I have to assign
the change permission to the customer support team which is slightly
dangerous. I have some models for which the customer support team needs
just the view access and not the change access because of security
issues. Any workaround to this?


Yes. You need to make the sensitive fields - or all fields - readonly in 
the admin depending on some property of the user. In my case "open data" 
is read-only for all users except for members of the company which owns 
the data ie., the user (or user_profile) with full access has a foreign 
key to the company concerned. But the result of any callable will do.


def open_data(self, request, obj=None):
"""Return the regular readonly fields or all fields as readonly if
the user is not a member of the company which owns the substance.


https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields
self is the admin.StackedInline instance
obj is the admin.ModelAdmin instance
"""

if not obj:
# some fields are readonly under all circumstances
return self.readonly_fields
else:
if obj.company == get_user_company(request.user):
return self.readonly_fields
else:
return self.model._meta.get_all_field_names()


So in admin.py ...

1. Nominate the permanently readonly fields as per the Admin docs

2. After readonly_fields make get_readonly_fields = open_data



2. Although the admin panel can be used as a CRM, are there any popular
CRM django apps than can be used instead of the admin panel?

--
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/6ac40e1a-d3e7-492f-9589-388ee95978db%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/562436F8.7020500%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Lack of View permission in Django

2015-10-18 Thread Ankit Agrawal
I have an active Django project where the admin panel is used by the 
customer support team. I have two questions -

1. Django lacks a `view` permission because of which I have to assign the 
change permission to the customer support team which is slightly dangerous. 
I have some models for which the customer support team needs just the view 
access and not the change access because of security issues. Any workaround 
to this?

2. Although the admin panel can be used as a CRM, are there any popular CRM 
django apps than can be used instead of the admin panel?

-- 
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/6ac40e1a-d3e7-492f-9589-388ee95978db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to develop a frontend web app for using REST services

2015-10-18 Thread bobhaugen
krmane, are you posting these same questions in the REST framework forum?

I'm guessing they would like a SQLAlchemy plugin.

Unlike you, however, I like their documentation, and have found the DRF 
gang to be responsive to issues.  That being said, I haven't actually used 
it in production yet. Just experimenting.

On Saturday, October 17, 2015 at 9:28:33 AM UTC-5, krmane wrote:
>
> Hi again,
> Xavier, I have gone through the main DRF documentation and also seen your 
> blog.
> I am wondering if you can send me an off line email which can explain the 
> relation between serializer and viewset?
> I have not got the concept clear, I am beginner to REST and all I 
> understand is that the response is generally in form of json.
> happy hacking.
> Krishnakant.
>
>
> On Friday 16 October 2015 03:39 PM, Xavier Ordoquy wrote:
>
> Hi, 
>
> I wrote a short blog post about getting most of Django REST framework 
> without using Django models.
>
> https://medium.com/@linovia/django-rest-framework-viewset-when-you-don-t-have-a-model-335a0490ba6f
>
> You will loose the integration with the Django Models and will need to do 
> a few things by yourself (pagination for example) but it’s still perfectly 
> possible to do that.
> Note that most of the documentation covers Django Models because it’s 
> where most of the options are. When you don’t use them, it’s up to the 
> developers to provide the content which will be very different from a 
> project to another.
>
> Hope this will help,
>
> Regards,
> Xavier,
> Linovia.
>
>
> Le 16 oct. 2015 à 12:00, kk < krm...@gmail.com > 
> a écrit :
>
> hello again,
> I haven't got my doubts solved but a few got added.
> I was again going through the tutorial on Django REST framework.
> I am trying to know if I can use a serialiser without tying it to the 
> DJango ORM or for that matter without tying it to any thing?
> I prefer using SQLAlchemy and get the data out using sql expression 
> language.
> Then I would like to convert this data to json format for sending as 
> response.
> Is this possible?
> Happy hacking.
> Krishnakant
>
>
> On Friday 16 October 2015 11:39 AM, kk wrote:
>
> Dear all.
> I got some very important suggestions from members of this list on using 
> Django for an accounting and inventory system, including Point of Sale.
> After the POS topic was discussed,
> OUr team decided to write a RESTfull server with all the business logic in 
> API.
> We plan to do this using some thing like Flask micro framework and then 
> write a complete web app using Django to consume these services.
> Of course it could be argued that why not use Django REST framework?
> But here I am a bit surprised as well as a bit disappointed.
> Contrary to what we have all seen and experienced about Django's 
> documentation, the rest framework is not at all comprehensively documented.
> I am still not totally understood the use of 
>
> serializers.HyperlinkedModelSerializer.
>  viewset is also not totally explained properly.  the tutorial is pretty fast 
> and confusing.
> I think a better example would have served it more understandable.
> Or perhaps the documentation there asumed that every one who reads it is a 
> Django as well as REST expert, even then it is confusing.
> Any ways coming back to the topic.
> So What suggestions could I get about my main query?
> happy hacking.
> Krishnakant.
>
>
>
> -- 
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> 
> https://groups.google.com/d/msgid/django-users/5620CACC.2060702%40gmail.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...@googlegroups.com .
> To post to this group, send email to django...@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/9872C498-CD0B-44A3-B64E-62A34F312C02%40linovia.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 

Re: Need example view on how to react on a webhook in Django

2015-10-18 Thread Daniel Roseman
On Friday, 16 October 2015 15:24:21 UTC+1, Sabine Maennel wrote:
>
> Hello,
>
> I tried to followed this Tutorial from Go Django, but I do not get it to 
> work. Can you please help me on how to react on a webhook in my application.
>
> *This is the tutorial,* that I tried to follow: 
> https://godjango.com/55-webhooks-django-and-ngrok/
>
> *This is my view:*
>
> # coding: utf-8
>
> from __future__ import unicode_literals, absolute_import
>
> import json
>
> from django.views.generic import View
>
> from braces.views import CsrfExemptMixin
>
> import logging
> logger = logging.getLogger(__name__)
>
> class ProcessHookView(CsrfExemptMixin, View):
> def post(self, request, args, *kwargs):
> print(json.loads(request.body))
> return HttpResponse()
>
>
> *url file: *
>
> # -*- coding: utf-8 -*-
>
> from __future__ import unicode_literals
>
> from django.conf.urls import patterns, include, url
> from .providers.hook import ProcessHookView, test_view, my_webhook_view
>
>
> urlpatterns = patterns('',
>
> url(r'^test$',
> ProcessHookView.as_view()),
>
> )
>
>
>
> The view does not work: I tried to call it with: 
>
> curl -X POST http://127.0.0.1:8000/de/webhooks/x -d '{"foo": "bar"}'
>
>
> and get this error:
>
> *[16/Oct/2015 16:09:57] "POST /de/webhooks/test HTTP/1.1" 500 112859*
>
>
> if I try the url directly I get this error:
>
> *[16/Oct/2015 16:10:20] "GET /de/webhooks/test HTTP/1.1" 405 0*
>
>
> What am I doing wrong? Is there an example on how to do it right? Do I 
> need Celery for this?
>
> Any help is highly appreciated
>
> with kind regards
>
> Sabine Maennel
>
>

Looks like the post you are following had a formatting problem, maybe 
thanks to conversion from Markdown. The signature of the `post` method 
should be:

def post(self, request, *args, **kwargs):

ie one asterisk before args, and two for kwargs.

Celery has nothing to do with this sort of thing - it's for offline 
processing. You might well want to trigger a Celery task from your webhook 
receiver, especially if the sender is expecting a quick response, but it's 
not required.
-- 
DR.

-- 
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/2b9c16d9-3f27-4f7f-bffd-d3db6fdfb2c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: save() prohibited to prevent data loss due to unsaved related object

2015-10-18 Thread Mike Dewhirst

On 18/10/2015 6:28 AM, Tim Graham wrote:

Do you have code that worked before (didn't result in data loss) but
doesn't work now? If so, it could be a bug in Django.


Yes indeed. It is all in my repo. I'll go back to 1.7.x and rerun the 
tests and report back.


Thanks

Mike



On Friday, October 16, 2015 at 8:30:07 PM UTC-4, Mike Dewhirst wrote:

I think I understand this error and I like what it does. My question
is ...

What is the necessary coding paradigm when you have all sorts of m:1,
1:m and m:m relationships and need to create those objects when they
don't exist when saving a new central object?

I'm moving from 1.7.x to 1.8.5 and this error seems like a show-stopper
at the moment.

Thanks

Mike

--
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/a96af71f-3ad2-4789-9c91-c297f5cf4f89%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/562339A3.2010603%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.