Re: How access verbose_name of a instance in template?

2014-11-05 Thread Mike Dewhirst

On 6/11/2014 2:29 PM, Neto wrote:

How access verbose_name of a instance in template?

I have:
car = Car.objects.get(pk=1)



Try this in a script somewhere to see if it returns the verbose name

def get_verbose_name(obj, field):
return 
obj.__class__()._meta.get_field_by_name('{0}'.format(field))[0].verbose_name


... and if so, you should be able to pass it into the template along 
with other items



In my template:

{{ car.color.??? }} {{ car.color }}

I wanna print the verbose_name, i want to it:

Color: red

--
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/1eaa4aba-1fe0-49b4-a397-381047b4c72a%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/545B05C8.4030105%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


How access verbose_name of a instance in template?

2014-11-05 Thread Neto
How access verbose_name of a instance in template?

I have:
car = Car.objects.get(pk=1)

In my template:

{{ car.color.??? }} {{ car.color }}

I wanna print the verbose_name, i want to it:

Color: red

-- 
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/1eaa4aba-1fe0-49b4-a397-381047b4c72a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to find the word 'python' in string 'pythonpythonpythonpyth'?

2014-11-05 Thread m1chael
does this help? http://www.nltk.org/

On Wed, Nov 5, 2014 at 7:28 PM, Russell Keith-Magee
 wrote:
>
> Actually - I'd suggest that the Python mailing list isn't the right place
> either.
>
> It sounds like the problem you're describing is called the Longest Repeated
> Substring problem:
>
> http://en.wikipedia.org/wiki/Longest_repeated_substring_problem
>
> The solution to this problem is well known, and O(n) - you use a suffix
> tree. Python doesn't have a built-in suffix tree (that I'm aware of), but
> it's a relatively simple task to build one using primitives that Python
> provides.
>
> Yours,
> Russ Magee %-)
>
> On Wed, Nov 5, 2014 at 7:50 PM, Denis Darii  wrote:
>>
>> Vitaly feel free to look on https://www.python.org/ for a solution to your
>> issue and please keep only django related questions in this "Django users"
>> group.
>> Thank you.
>> Denis.
>>
>> On 5 November 2014 12:41, Віталій Лисенко  wrote:
>>>
>>> Sorry. I asked the question incorrectly.
>>> Example.
>>> I line 'pythonpythonpyth'. How do I know which word is the foundation
>>> line?.
>>> Other examples:
>>> "DOLORIUMD" --> rigth answer DOLORIUM
>>> "HELLOL" --> HELLOL
>>> "thewordword" --> thewordword
>>>
>>> I need to know whether the word in the text is repeated and get it. This
>>> will be the key.
>>>
>>> On 5 November 2014 13:22, Rafael E. Ferrero 
>>> wrote:

 a.find('python')


 --
 Rafael E. Ferrero

 2014-11-05 8:16 GMT-03:00 Віталій Лисенко :
>
> How to find the word 'python' in string 'pythonpythonpythonpyth'?
>
> --
> 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/5cb8f985-b3aa-4df7-aed7-6a1859e7a87c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


 --
 You received this message because you are subscribed to a topic in the
 Google Groups "Django users" group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/django-users/xNEunhaILUI/unsubscribe.
 To unsubscribe from this group and all its topics, 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/CAJJc_8X3nEz5t7TF6cJ4thQOt5T8SLCqLpCE6xS-tT7sR7832g%40mail.gmail.com.

 For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>
>>>
>>> --
>>> Best regards Vitaly Lysenko from village Markove (Ukraine)
>>>
>>> --
>>> 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/CAJJKi7dz45x0sf7vBRyOOTOwr6F_Tu3bbwv0o4wzEtsWUVe-%3DA%40mail.gmail.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> I'm using Linux because i'm freedom dependent.
>>
>> --
>> 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/CAGyQdPrip8ccCmX9LjTLu55BmNmhZHNbvKf-MiRmG%2BZyPmo9Hg%40mail.gmail.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/CAJxq84_j39%2BG4G0MONUKNB12qVv-Y6TOYCAgAnB0GPHxmr%3Dkqw%40mail.gmail.com.

Re: How to find the word 'python' in string 'pythonpythonpythonpyth'?

2014-11-05 Thread Russell Keith-Magee
Actually - I'd suggest that the Python mailing list isn't the right place
either.

It sounds like the problem you're describing is called the Longest Repeated
Substring problem:

http://en.wikipedia.org/wiki/Longest_repeated_substring_problem

The solution to this problem is well known, and O(n) - you use a suffix
tree. Python doesn't have a built-in suffix tree (that I'm aware of), but
it's a relatively simple task to build one using primitives that Python
provides.

Yours,
Russ Magee %-)

On Wed, Nov 5, 2014 at 7:50 PM, Denis Darii  wrote:

> Vitaly feel free to look on https://www.python.org/ for a solution to
> your issue and please keep only django related questions in this "Django
> users" group.
> Thank you.
> Denis.
>
> On 5 November 2014 12:41, Віталій Лисенко  wrote:
>
>> Sorry. I asked the question incorrectly.
>> Example.
>> I line 'pythonpythonpyth'. How do I know which word is the foundation
>> line?.
>> Other examples:
>> "DOLORIUMD" --> rigth answer DOLORIUM
>> "HELLOL" --> HELLOL
>> "thewordword" --> thewordword
>>
>> I need to know whether the word in the text is repeated and get it. This
>> will be the key.
>>
>> On 5 November 2014 13:22, Rafael E. Ferrero 
>> wrote:
>>
>>> a.find('python')
>>>
>>>
>>> --
>>> Rafael E. Ferrero
>>>
>>> 2014-11-05 8:16 GMT-03:00 Віталій Лисенко :
>>>
 How to find the word 'python' in string 'pythonpythonpythonpyth'?

 --
 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/5cb8f985-b3aa-4df7-aed7-6a1859e7a87c%40googlegroups.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/django-users/xNEunhaILUI/unsubscribe.
>>> To unsubscribe from this group and all its topics, 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/CAJJc_8X3nEz5t7TF6cJ4thQOt5T8SLCqLpCE6xS-tT7sR7832g%40mail.gmail.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Best regards Vitaly Lysenko from village Markove (Ukraine)
>>
>> --
>> 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/CAJJKi7dz45x0sf7vBRyOOTOwr6F_Tu3bbwv0o4wzEtsWUVe-%3DA%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> I'm using Linux because i'm freedom dependent.
>
> --
> 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/CAGyQdPrip8ccCmX9LjTLu55BmNmhZHNbvKf-MiRmG%2BZyPmo9Hg%40mail.gmail.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, 

Enter a contest to win a free e-copy of "Web Development with Django Cookbook"

2014-11-05 Thread Aidas Bendoraitis
Hello all,

Not long ago my book "Web Development with Django Cookbook" was published 
and now you have a chance to win a free copy of it.

Check 
http://djangotricks.blogspot.de/2014/11/win-free-copies-of-web-development-with-django-cookbook.html
 
for more details.

Cheers,
Aidas Bendoraitis

-- 
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/b4e1540c-88b9-4c55-a151-95ceddd8b8b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using ContentType to link two different objects together

2014-11-05 Thread Some Developer


On 05/11/2014 18:47, Carl Meyer wrote:

On 11/05/2014 11:35 AM, Some Developer wrote:

On 05/11/2014 18:16, Carl Meyer wrote:

On 11/05/2014 11:09 AM, Some Developer wrote:

I'm trying to write my own implementation of the Django comments
framework for various reasons and am wondering how one would link
comments to a particular object (model) of another type. For instance I
could have a ForeignKey in the Comment model pointing to a Blog post
article but that would mean that you could only leave comments on Blog
post articles. I want to be able to configure my Comment model so that
it can link to any other object of any type.

Does anyone know how to do that? I think it has something to do with the
ContentType framework that comes with Django but I have never used it
before so I'm not entirely sure.

I think this is what you're looking for:
https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations

However, by using GenericForeignKey you give up some valuable things:
the database can no longer enforce referential integrity on those
relationships, and joins become more complex and often slower. So I
would recommend at least considering alternatives.

One possible alternative is to instead provide the bulk of your Comment
model as an abstract base model class, and then have users of your
comment app create their own Comment model inheriting from your abstract
base, and adding a single FK to whatever model they want comments on.
(This presumes that most users of your comments app will only need
comments on a single model in a given system; or if they want comments
on more than one model, they don't mind having two separate Comment
models to handle that.)

Thanks for the info. You make some interesting points about the database
not being able to enforce referential integrity.

I hadn't thought of providing the comment model as a base class and
having the users specialise it themselves. How would that work in
regards to template tags? For instance if I had a template tag like this:

{% get_comments for obj as var %}

how would one hook in a user provided object with its own model which is
not known ahead of time

In order to make this template tag work, your comments app just needs to
know what comment model exists for any given "commentable" model. You
could ask the user to explicitly tell you this, by calling some kind of
registration function. Or you can just listen to the `class_prepared`
signal [1], which fires after every model class is prepared; check if
the model class is a subclass of your abstract Comment base; if it is,
check for the required added FK (throw a clear error if they didn't add
it), see what model class it's pointing to, and add it to your registry.

or would you suggest using a template tag such

as this instead? I guess letting the user explicitly state the
application and the model themselves offers the best flexibility in the
long run.

{% get_comments for [app].[model] [object_id] %}

I don't think this variant of the template tag really helps anything;
given an `obj`, you can quite easily figure out what model class it's an
instance of (`obj.__class__` or `obj._meta.model`). You still have to
get from that "commentable" model class to its comment model class,
which requires the same registry I described above.

So I'd probably go with the first version, which is an easier API for
the template author.

Carl


[1] https://docs.djangoproject.com/en/1.7/ref/signals/#class-prepared



Cool. Thanks for the advice. I'll give it a go using the first template 
tag syntax and see what happens. I've never written a template tag 
library myself before so this will be a bit of a learning experience for 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/545A8084.7000600%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelMultipleChoiceField forcing required

2014-11-05 Thread Scot Hacker


On Wednesday, November 5, 2014 11:15:47 AM UTC-8, Carl Meyer wrote:


>
> So because you are manually creating your `instructors` and `students` 
> fields on the form, the `blank=True` in the model has no effect; you 
> need to pass `required=False` to your two form fields. 
>

Got it, right you are - that works fine. 
 

>
> (Because of this, I frequently choose to update/tweak form fields in an 
> overridden `__init__` method of a ModelForm, rather than overriding the 
> fields entirely.) 
>
>
Makes sense! 

Thanks,
./s
 

-- 
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/ff79b372-a8d0-4c39-ab62-277fd4869a1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelMultipleChoiceField forcing required

2014-11-05 Thread Carl Meyer
Hi Scot,

On 11/05/2014 12:11 PM, Scot Hacker wrote:
> I'm having a strange issue with a pair of ManyToManyFields, where
> they're acting like they're required fields in the admin even though
> they're not.
> 
> 
> # In models.py
> |
> instructors =models.ManyToManyField(Instructor,blank=True)
> students =models.ManyToManyField(Profile,blank=True)
> 
> |
> 
> 
> I can update an instance of this model with no instructors or students
> from the CLI just fine. The fields are not required. But I'm using
> ModelMultipleChoiceField in the admin:
> 
> 
> # In admin.py
> |
> classOfferingAdminForm(forms.ModelForm):
> 
> instructors =forms.ModelMultipleChoiceField(
> widget
> =widgets.FilteredSelectMultiple('Instructors',is_stacked=False),
> queryset =Instructor.objects.all())
> 
> 
> students =forms.ModelMultipleChoiceField(
> widget =widgets.FilteredSelectMultiple('Students',is_stacked=False),
> queryset =User.objects.filter(is_active=True))
> |
> 
> and when I try to save via the admin, it tells me these fields are
> required. If I tweak it to not use this ModelForm, I can save without
> instructors or students just fine. 

When you override a field in a ModelForm, you lose the ability for it to
automatically pick up configuration from the model field. Either the
field is auto-created by the ModelForm based on your model field, or it
is created manually by you; it can't be both.

So because you are manually creating your `instructors` and `students`
fields on the form, the `blank=True` in the model has no effect; you
need to pass `required=False` to your two form fields.

(Because of this, I frequently choose to update/tweak form fields in an
overridden `__init__` method of a ModelForm, rather than overriding the
fields entirely.)

Carl

-- 
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/545A773C.8080200%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


Re: Django and Ajax, Django not returning posted data.

2014-11-05 Thread G Z
updated my ajax to the following but for somereason it just says something 
went wrong



$(document).ready(function() {
$('#get_info').submit(function() {
$.ajax({
type: "POST",
url: "/vmstatus/",
dataType: "json",
async: true,
data: {
csrfmiddlewaretoken: '{{csrf_token}}',
selected_customer: $('selected_customer').val()
},
success: function (json) {
console.log('done');
setInterval(returnData, 5000);  
console.log(json);
},
error: function(json) {
console.log('something went wrong');
console.log(json);
}
});
return false;
});
});

var returnData = function () {
$.ajax({
type: "POST",
url: "/vmstatus/",
dataType: "json",
async: true,
data: {
csrfmiddlewaretoken: '{{csrf_token}}',
selected_customer: $('selected_customer').val()
},
success: function (json) {
console.log('done');
console.log(json);
},
error: function(json) {
console.log('something went wrong');
console.log(json);
}
});
};  





-- 
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/6d192f9a-7128-405e-87ce-785589f09b80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to restrict a class based view to one user group?

2014-11-05 Thread Daniel Grace
Hi,
Say I have a function as follows:

def is_supervisor(user):
return user.groups.filter(name='supervisor').exists()

...and a CBV for deleting records:

class DeleteFlow(DeleteView):
# etc...

How can I restrict access to this view using the function?
I understand that this may be possible with a mixin, but how?
Or is there a better way?

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/cef271fb-b6e9-4e86-88d6-0bad8a90b0bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ModelMultipleChoiceField forcing required

2014-11-05 Thread Scot Hacker
I'm having a strange issue with a pair of ManyToManyFields, where they're 
acting like they're required fields in the admin even though they're not.


# In models.py
instructors = models.ManyToManyField(Instructor, blank=True)
students = models.ManyToManyField(Profile, blank=True)



I can update an instance of this model with no instructors or students from 
the CLI just fine. The fields are not required. But I'm using 
ModelMultipleChoiceField in the admin:


# In admin.py
class OfferingAdminForm(forms.ModelForm):

instructors = forms.ModelMultipleChoiceField(
widget = widgets.FilteredSelectMultiple('Instructors',is_stacked=
False),
queryset = Instructor.objects.all())


students = forms.ModelMultipleChoiceField(
widget = widgets.FilteredSelectMultiple('Students',is_stacked=False
),
queryset = User.objects.filter(is_active=True))

and when I try to save via the admin, it tells me these fields are 
required. If I tweak it to not use this ModelForm, I can save without 
instructors or students just fine. 

Theories? 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/b99c64ec-d6af-4716-8d86-5f93bd00af0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using ContentType to link two different objects together

2014-11-05 Thread Carl Meyer
On 11/05/2014 11:35 AM, Some Developer wrote:
> On 05/11/2014 18:16, Carl Meyer wrote:
>> On 11/05/2014 11:09 AM, Some Developer wrote:
>>> I'm trying to write my own implementation of the Django comments
>>> framework for various reasons and am wondering how one would link
>>> comments to a particular object (model) of another type. For instance I
>>> could have a ForeignKey in the Comment model pointing to a Blog post
>>> article but that would mean that you could only leave comments on Blog
>>> post articles. I want to be able to configure my Comment model so that
>>> it can link to any other object of any type.
>>>
>>> Does anyone know how to do that? I think it has something to do with the
>>> ContentType framework that comes with Django but I have never used it
>>> before so I'm not entirely sure.
>> I think this is what you're looking for:
>> https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations
>>
>> However, by using GenericForeignKey you give up some valuable things:
>> the database can no longer enforce referential integrity on those
>> relationships, and joins become more complex and often slower. So I
>> would recommend at least considering alternatives.
>>
>> One possible alternative is to instead provide the bulk of your Comment
>> model as an abstract base model class, and then have users of your
>> comment app create their own Comment model inheriting from your abstract
>> base, and adding a single FK to whatever model they want comments on.
>> (This presumes that most users of your comments app will only need
>> comments on a single model in a given system; or if they want comments
>> on more than one model, they don't mind having two separate Comment
>> models to handle that.)
> 
> Thanks for the info. You make some interesting points about the database
> not being able to enforce referential integrity.
> 
> I hadn't thought of providing the comment model as a base class and
> having the users specialise it themselves. How would that work in
> regards to template tags? For instance if I had a template tag like this:
> 
> {% get_comments for obj as var %}
> 
> how would one hook in a user provided object with its own model which is
> not known ahead of time 

In order to make this template tag work, your comments app just needs to
know what comment model exists for any given "commentable" model. You
could ask the user to explicitly tell you this, by calling some kind of
registration function. Or you can just listen to the `class_prepared`
signal [1], which fires after every model class is prepared; check if
the model class is a subclass of your abstract Comment base; if it is,
check for the required added FK (throw a clear error if they didn't add
it), see what model class it's pointing to, and add it to your registry.

or would you suggest using a template tag such
> as this instead? I guess letting the user explicitly state the
> application and the model themselves offers the best flexibility in the
> long run.
> 
> {% get_comments for [app].[model] [object_id] %}

I don't think this variant of the template tag really helps anything;
given an `obj`, you can quite easily figure out what model class it's an
instance of (`obj.__class__` or `obj._meta.model`). You still have to
get from that "commentable" model class to its comment model class,
which requires the same registry I described above.

So I'd probably go with the first version, which is an easier API for
the template author.

Carl


[1] https://docs.djangoproject.com/en/1.7/ref/signals/#class-prepared

-- 
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/545A70B4.5060907%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


Re: Using ContentType to link two different objects together

2014-11-05 Thread Some Developer


On 05/11/2014 18:16, Carl Meyer wrote:

Hi,

On 11/05/2014 11:09 AM, Some Developer wrote:

I'm trying to write my own implementation of the Django comments
framework for various reasons and am wondering how one would link
comments to a particular object (model) of another type. For instance I
could have a ForeignKey in the Comment model pointing to a Blog post
article but that would mean that you could only leave comments on Blog
post articles. I want to be able to configure my Comment model so that
it can link to any other object of any type.

Does anyone know how to do that? I think it has something to do with the
ContentType framework that comes with Django but I have never used it
before so I'm not entirely sure.

I think this is what you're looking for:
https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations

However, by using GenericForeignKey you give up some valuable things:
the database can no longer enforce referential integrity on those
relationships, and joins become more complex and often slower. So I
would recommend at least considering alternatives.

One possible alternative is to instead provide the bulk of your Comment
model as an abstract base model class, and then have users of your
comment app create their own Comment model inheriting from your abstract
base, and adding a single FK to whatever model they want comments on.
(This presumes that most users of your comments app will only need
comments on a single model in a given system; or if they want comments
on more than one model, they don't mind having two separate Comment
models to handle that.)

Carl


Thanks for the info. You make some interesting points about the database 
not being able to enforce referential integrity.


I hadn't thought of providing the comment model as a base class and 
having the users specialise it themselves. How would that work in 
regards to template tags? For instance if I had a template tag like this:


{% get_comments for obj as var %}

how would one hook in a user provided object with its own model which is 
not known ahead of time or would you suggest using a template tag such 
as this instead? I guess letting the user explicitly state the 
application and the model themselves offers the best flexibility in the 
long run.


{% get_comments for [app].[model] [object_id] %}

--
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/545A6DDD.5050702%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django and Ajax, Django not returning posted data.

2014-11-05 Thread G Z
Another note is I try to return posted data and out put it to the html for 
testing and that doesn't get returned either.

-- 
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/31f12244-a35c-4efa-9add-332c6ab728b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django and Ajax, Django not returning posted data.

2014-11-05 Thread G Z
So I'm trying to write an ajax script that post data to django without 
having to leave the page. Currently it is on submit however eventually im 
going to put it on a timer.

Right now the function outputs to the console as a success but no data is 
returned from django.


Here is my ajax


$(document).ready(function() {
$('#get_info').submit(function() { 
$.ajax({
type: $('#get_info').attr('POST'),
url: $('#get_info').attr('action'),
data: $('#get_info').serialize(),
success: function (data) {
console.log('done');
console.log($('#get_info').serialize());
},
error: function(data) {
console.log('something went wrong');
}
});
return false;
});
});


Here is the serialized data it outputs to the console.

"done" vmstatus:34
"csrfmiddlewaretoken=HApMk9LWlxNUdlJaD4kj0WZkCTki4hin_customer=24=True"

However no django data is returned after that? I know the django code works 
because I was using regular form submission to test it.

here is my views code:

   if request.method == 'POST':   
  posted_data = request.POST.copy()
  customer_id = int(posted_data['selected_customer'])
  for customer in customers:
 if customer.customer_id == customer_id:
selected_customer = ((decrypt('secretkey', customer.
customer_name), int(customer.customer_id)))   
 customer_list.append((decrypt('secretkey', customer.customer_name), 
int(customer.customer_id))) 
 
  
  vms = PortalCommandCenter.objects.filter(customer_id = customer_id).
distinct('vm_id')
  
   
  context = {'user.is_superuser':user.is_superuser, 
'customer_list':customer_list,
'customer_id':customer_id,
'vms':vms,
'posted_data':posted_data,
'selected_customer':selected_customer
 }
 
  return render(request, 'vmstatus.html', context) 

do I need to serialize the data as json so that it is still a dictionary if 
so how do I 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/75ce4888-933c-461a-8709-35bb7cfdd216%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using ContentType to link two different objects together

2014-11-05 Thread Carl Meyer
Hi,

On 11/05/2014 11:09 AM, Some Developer wrote:
> I'm trying to write my own implementation of the Django comments
> framework for various reasons and am wondering how one would link
> comments to a particular object (model) of another type. For instance I
> could have a ForeignKey in the Comment model pointing to a Blog post
> article but that would mean that you could only leave comments on Blog
> post articles. I want to be able to configure my Comment model so that
> it can link to any other object of any type.
> 
> Does anyone know how to do that? I think it has something to do with the
> ContentType framework that comes with Django but I have never used it
> before so I'm not entirely sure.

I think this is what you're looking for:
https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations

However, by using GenericForeignKey you give up some valuable things:
the database can no longer enforce referential integrity on those
relationships, and joins become more complex and often slower. So I
would recommend at least considering alternatives.

One possible alternative is to instead provide the bulk of your Comment
model as an abstract base model class, and then have users of your
comment app create their own Comment model inheriting from your abstract
base, and adding a single FK to whatever model they want comments on.
(This presumes that most users of your comments app will only need
comments on a single model in a given system; or if they want comments
on more than one model, they don't mind having two separate Comment
models to handle that.)

Carl

-- 
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/545A696F.8090403%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


Using ContentType to link two different objects together

2014-11-05 Thread Some Developer

Hi,

I'm trying to write my own implementation of the Django comments 
framework for various reasons and am wondering how one would link 
comments to a particular object (model) of another type. For instance I 
could have a ForeignKey in the Comment model pointing to a Blog post 
article but that would mean that you could only leave comments on Blog 
post articles. I want to be able to configure my Comment model so that 
it can link to any other object of any type.


Does anyone know how to do that? I think it has something to do with the 
ContentType framework that comes with Django but I have never used it 
before so I'm not entirely sure.


Any help is appreciated.

--
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/545A67F6.9010606%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


Re: running unit tests with legacy database: Error 1050, Table already exists

2014-11-05 Thread Collin Anderson
Hi David,

Interesting. Shouldn't the test database be a separate, fresh, empty 
database (not a legacy database)?

Thanks,
Collin

-- 
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/b79d8ab2-38ef-489d-9563-c2474c58defb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Global Variable

2014-11-05 Thread Collin Anderson
Hello,

You could also try creating an assignment tag something like:

{% get_base_url as base_url %}

https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#assignment-tags

That way you don't need to deal with context_processors.

Collin

-- 
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/f03981cf-68cc-4a52-8d34-2869ef4af412%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why does django use mysqldb over mysql-connector?

2014-11-05 Thread Collin Anderson
Hello,
 

> https://github.com/PyMySQL/mysqlclient-python
>
> I didn't tried that. Someone use it?
>

I use it.

There's a thread about it on django-developers.
https://groups.google.com/d/topic/django-developers/n-TI8mBcegE/discussion

Collin
 

-- 
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/4cd41609-5ea0-4b19-9a45-bb7c867dada8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle exceptions in RequestContext?

2014-11-05 Thread Carl Meyer
Hi Daniel,

On 11/05/2014 08:44 AM, Daniel Grace wrote:
> I see where you are coming from Carl, thanks for the information.  Do
> you have a suitable example of where one might put error handling in the
> view code?

Usually I try to keep view code as short and simple as possible (because
it is the least reusable and hardest to test), pushing complexity into
more-reusable utility functions, form classes, etc instead. So it's
quite unusual for me to have an `except` statement directly in a view. I
checked my current project and here's the one case I found:

def oauth_callback(request, provider_key):
"""OAuth authorization callback for a specific provider."""
state = request.session.get('oauth_state', '')
provider = get_provider_or_404(None, provider_key, state=state)
auth_response = request.build_absolute_uri()
try:
user = provider.authorize(auth_response)
except UserConstraintError as exc:
messages.warning(
request,
"Cannot create or update user: "
"%s '%s' is invalid or already taken." % (exc.field, exc.value),
)
else:
if user is None:
messages.warning(request, "Unable to link account.")
else:
user.backend = settings.AUTHENTICATION_BACKENDS[0]
login(request, user)
return redirect('home')


A couple things to note here:

1. The `try:` block wraps only one statement. It's very rare that
there's a good case to have more than one statement in a `try` block
(unless it's a `try/finally` instead of `try/except`).

2. The `except` block catches one very specific exception class that I
expect `provider.authorize` might raise. The goal is to handle a
specific scenario; unexpected errors shouldn't pass silently.

3. As someone else in this thread already suggested, I'm handling the
error cases here by using `django.contrib.messages` to display an error
message.

Hope that helps,

Carl

-- 
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/545A5E2F.5050005%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple versions of python on linux server

2014-11-05 Thread Collin Anderson
Hello,
 

> You have to use a mod_wsgi that is built against python3. On 
> Debian/Ubuntu, the package is called libapache2-mod-wsgi-py3.
>
Also, there's an Red Hat package of mod_wsgi built against python 3.3 here:
http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/repoview/python33-mod_wsgi.html

The modwsgi list could probably give you even better 
advice. https://groups.google.com/d/forum/modwsgi

Collin

-- 
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/3c04651f-6987-4a73-89e0-67094f30a4d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django expat error

2014-11-05 Thread Amal Francis
I have a fresh installation of Django 1.7 on virtualenv. When i run the 
migration python manage.py migrate am getting 

from xml.sax.expatreader import ExpatParser as _ExpatParser
  File "/usr/lib/python2.7/xml/sax/expatreader.py", line 24, in 
raise SAXReaderNotAvailable("expat not supported", None)
xml.sax._exceptions.SAXReaderNotAvailable: expat not supported

I am using ubuntu 14.04. Any help, please?
Thanks in advance.

-- 
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/fce8636c-0dfc-4cd0-9830-23c3fe43bff4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit-testing Custom Admin Action, requires request and querysets parameters.

2014-11-05 Thread Collin Anderson
Hello,

Would it work to import AppAdmin, instantiate it, and then call the methods 
in a unit test?

Collin
 

-- 
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/9338e316-a58c-4ec1-a67a-47c52ffba1bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle exceptions if RequestContext fails?

2014-11-05 Thread Collin Anderson
Hi Daniel,

Would it work to pass in an empty Context? You could also as you say, try 
using render() to see if it would work.

Collin

-- 
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/55a99dec-2887-414f-a712-56d409d6f743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django REST Framework: How to add prefix in URL for versioning

2014-11-05 Thread Lee Hinde
Swap the urls:

 url(r'^v1/', include(v1_urls, namespace="v1"))

url(r'^', include(default_urls, namespace="default")),


On Wed, Nov 5, 2014 at 5:01 AM, Shoaib Ijaz  wrote:

> I am trying to create version for REST application. Here is my URL Examle
>
> www.myapi.com/foo [default version]
> www.myapi.com/v1/foo [version one]
>
> This is the project structure
>
> ├── __init__.py├── settings.py├── urls.py├── default_app│ ├── __init__.py│ 
> ├── serializer.py│ ├── models.py│ ├── views.py│ ├── urls.py│ └── v1_app├── 
> __init__.py├── serializer.py├── models.py├── views.py├── urls.py
>
> *default_app urls.py*
>
> from django.conf.urls import *from default_app import views as df_viewsfrom 
> rest_framework import routers
>
> router = routers.DefaultRouter()
> router.register(r'foo', df_views.viewname, "foo")
> urlpatterns = router.urls
>
> *v1_app urls.py*
>
> from django.conf.urls import *from v1_app import views as ver_viewsfrom 
> rest_framework import routers
>
> router = routers.DefaultRouter()
> router.register(r'foo', ver_views.viewname, "foo")
> urlpatterns = router.urls
>
> *main file for urls.py*
>
> from django.conf.urls import patterns, include, urlfrom defualt_app import 
> urls as default_urlsfrom v1_app import urls as v1_urlsfrom 
> django.contrib.staticfiles.urls import staticfiles_urlpatterns
>
>
>
> urlpatterns += patterns('',
> url(r'^', include(default_urls, namespace="default")),
> url(r'^v1/', include(v1_urls, namespace="v1")))
>
> urlpatterns += staticfiles_urlpatterns()
>
> My issue is, when i using simple url without any prefix then it is working
>
> www.myapi.com/foo
>
> and when i used version prefix v1 or v2 then it throws error [Page not
> found (404)]
>
> www.myapi.com/v1/foo
>
> I got this idea from this link http://stackoverflow.com/a/21839842/1558544
>
> If I don't use middleware class then is this possible to get same result?
>
> Thank you
>
>
>

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


Re: How to handle exceptions in RequestContext?

2014-11-05 Thread Daniel Grace
I see where you are coming from Carl, thanks for the information.  Do you 
have a suitable example of where one might put error handling in the view 
code?

-- 
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/80383391-50b5-4cda-a793-25b4479b7c69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple site package directories for Python and question about apache configuration

2014-11-05 Thread Scot Hacker
 

You want to establish the path directories in your .wsgi file. Use 
`addsitedir` to set the path to site-packages and set additional paths with 
path.append, e.g.:

import os, sys, site

site.addsitedir('/path/to/site-packages')

sys.path.append('/extra/path/1')

sys.path.append('/extra/path/2')



On Tuesday, November 4, 2014 4:26:12 AM UTC-8, robert brook wrote:
>
> I see that there are 2 paths in my application for site packages.
>
> How do I configure Apache to use the 2 packages.
>
> A typical entry in Apache is
>
> WSGIPythonPath 
> /path/to/mysite.com:/path/to/your/venv/lib/python3.X/site-packages
>
> Can I specify 2 paths to represent the 2 locations of site packages.
> And what would the syntax be?
>
> On Monday, November 3, 2014 4:15:59 PM UTC-5, Aliane Abdelouahab wrote:
>>
>> On linux, python installs libs in diffferents places: for example in open 
>> suse, when you install it the first time, and you choose python and some 
>> third party libraries, and then when you will do setup.py for a library you 
>> download, they will be in different locations!
>> http://stackoverflow.com/a/12950101/861487
>>
>> Le lundi 3 novembre 2014 21:24:17 UTC+1, robert brook a écrit :
>>>
>>> I overlooked mentioning that the path command returned 2 different 
>>> locations for the 3 modules.
>>> Not sure why one package got installed in the lib64 path.  They were all 
>>> installed with the setup.py install command.
>>>
>>> On Monday, November 3, 2014 3:18:06 PM UTC-5, robert brook wrote:

 I am building the web application on a linux red hat machine.

 I was trying to pull the path for the site packages for the 3 modules 
 that I have installed so that I can specify the path in the apache config 
 file

 Can I specify 2 paths in Apache?

 Thanks



 >>> import django

 >>> print (django.__path__)

 ['*/opt/rh/python33/root/usr/lib/python3.3/site-packages/*
 Django-1.7-py3.3.egg/django']

  >>> import sql_server.pyodbc

 >>> print (sql_server.pyodbc.__path__)

 ['/opt/rh/python33/root/usr/*lib*
 /python3.3/site-packages/django_pyodbc_azure-1.2.0-py3.3.egg/sql_server/pyodbc']

   

 >>> import sqlalchemy

 >>> print (sqlalchemy.__path__)

 ['/opt/rh/python33/root/usr/*lib64*
 /python3.3/site-packages/SQLAlchemy-0.9.7-py3.3-linux-x86_64.egg/sqlalchemy']

 >>> 

>>>

-- 
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/5f62bd18-f5ed-418f-8e78-181433c353c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django REST Framework: How to add prefix in URL for versioning

2014-11-05 Thread Shoaib Ijaz


I am trying to create version for REST application. Here is my URL Examle

www.myapi.com/foo [default version]
www.myapi.com/v1/foo [version one]

This is the project structure

├── __init__.py├── settings.py├── urls.py├── default_app│ ├── __init__.py│ ├── 
serializer.py│ ├── models.py│ ├── views.py│ ├── urls.py│ └── v1_app├── 
__init__.py├── serializer.py├── models.py├── views.py├── urls.py

*default_app urls.py*

from django.conf.urls import *from default_app import views as df_viewsfrom 
rest_framework import routers

router = routers.DefaultRouter()
router.register(r'foo', df_views.viewname, "foo")
urlpatterns = router.urls

*v1_app urls.py*

from django.conf.urls import *from v1_app import views as ver_viewsfrom 
rest_framework import routers

router = routers.DefaultRouter()
router.register(r'foo', ver_views.viewname, "foo")
urlpatterns = router.urls

*main file for urls.py*

from django.conf.urls import patterns, include, urlfrom defualt_app import urls 
as default_urlsfrom v1_app import urls as v1_urlsfrom 
django.contrib.staticfiles.urls import staticfiles_urlpatterns



urlpatterns += patterns('',
url(r'^', include(default_urls, namespace="default")),
url(r'^v1/', include(v1_urls, namespace="v1")))

urlpatterns += staticfiles_urlpatterns()

My issue is, when i using simple url without any prefix then it is working

www.myapi.com/foo

and when i used version prefix v1 or v2 then it throws error [Page not 
found (404)]

www.myapi.com/v1/foo

I got this idea from this link http://stackoverflow.com/a/21839842/1558544

If I don't use middleware class then is this possible to get same result?

Thank you

-- 
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/42d759fb-19f2-483f-a979-1b61cce51d57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to find the word 'python' in string 'pythonpythonpythonpyth'?

2014-11-05 Thread Denis Darii
Vitaly feel free to look on https://www.python.org/ for a solution to your
issue and please keep only django related questions in this "Django users"
group.
Thank you.
Denis.

On 5 November 2014 12:41, Віталій Лисенко  wrote:

> Sorry. I asked the question incorrectly.
> Example.
> I line 'pythonpythonpyth'. How do I know which word is the foundation
> line?.
> Other examples:
> "DOLORIUMD" --> rigth answer DOLORIUM
> "HELLOL" --> HELLOL
> "thewordword" --> thewordword
>
> I need to know whether the word in the text is repeated and get it. This
> will be the key.
>
> On 5 November 2014 13:22, Rafael E. Ferrero 
> wrote:
>
>> a.find('python')
>>
>>
>> --
>> Rafael E. Ferrero
>>
>> 2014-11-05 8:16 GMT-03:00 Віталій Лисенко :
>>
>>> How to find the word 'python' in string 'pythonpythonpythonpyth'?
>>>
>>> --
>>> 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/5cb8f985-b3aa-4df7-aed7-6a1859e7a87c%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/xNEunhaILUI/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/CAJJc_8X3nEz5t7TF6cJ4thQOt5T8SLCqLpCE6xS-tT7sR7832g%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Best regards Vitaly Lysenko from village Markove (Ukraine)
>
> --
> 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/CAJJKi7dz45x0sf7vBRyOOTOwr6F_Tu3bbwv0o4wzEtsWUVe-%3DA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
I'm using Linux because i'm freedom dependent.

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


Re: How to find the word 'python' in string 'pythonpythonpythonpyth'?

2014-11-05 Thread Віталій Лисенко
Sorry. I asked the question incorrectly.
Example.
I line 'pythonpythonpyth'. How do I know which word is the foundation line?.
Other examples:
"DOLORIUMD" --> rigth answer DOLORIUM
"HELLOL" --> HELLOL
"thewordword" --> thewordword

I need to know whether the word in the text is repeated and get it. This
will be the key.

On 5 November 2014 13:22, Rafael E. Ferrero 
wrote:

> a.find('python')
>
>
> --
> Rafael E. Ferrero
>
> 2014-11-05 8:16 GMT-03:00 Віталій Лисенко :
>
>> How to find the word 'python' in string 'pythonpythonpythonpyth'?
>>
>> --
>> 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/5cb8f985-b3aa-4df7-aed7-6a1859e7a87c%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/xNEunhaILUI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAJJc_8X3nEz5t7TF6cJ4thQOt5T8SLCqLpCE6xS-tT7sR7832g%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Best regards Vitaly Lysenko from village Markove (Ukraine)

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


Re: How to find the word 'python' in string 'pythonpythonpythonpyth'?

2014-11-05 Thread Rafael E. Ferrero
a.find('python')


--
Rafael E. Ferrero

2014-11-05 8:16 GMT-03:00 Віталій Лисенко :

> How to find the word 'python' in string 'pythonpythonpythonpyth'?
>
> --
> 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/5cb8f985-b3aa-4df7-aed7-6a1859e7a87c%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/CAJJc_8X3nEz5t7TF6cJ4thQOt5T8SLCqLpCE6xS-tT7sR7832g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to find the word 'python' in string 'pythonpythonpythonpyth'?

2014-11-05 Thread Віталій Лисенко
How to find the word 'python' in string 'pythonpythonpythonpyth'?

-- 
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/5cb8f985-b3aa-4df7-aed7-6a1859e7a87c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Beginner: ManyToManyFields error creating the model / adding values by the Admin Module or the Shell

2014-11-05 Thread Erik Cederstrand
> Den 04/11/2014 kl. 23.07 skrev lnzy3...@gmx.de:
> 
>  
> Hi Erik,
>  
> the idea was, that one Author can write in more than one language (eg. en and 
> de), or no one at all. This was the background to use the ManyToManyField. 

Yes, but then you simply create multiple Interest objects, right? One for every 
author-language combination. Your field names are singular, not plural, which 
tells me you should use a ForeignKey field. The current Interest model links 
multiple Authors with multiple Languages, which doesn't make much sense.

If you want to use ManyToManyField, then you put a "interests" field to 
Language directly on the Author model.

> But the "error" Message must have an other reason?

The direct cause is that you are trying to print self.author in the __str__ 
method. self.author is a ManyRelatedManager, so you should use 
self.authors.all() to access the individual authors. But you should change you 
models instead of fixing this error :-)

Erik

-- 
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/EBA3FC7E-EECC-47A7-9C4D-357F4B7295C8%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.