Re: Query question

2015-08-17 Thread Dheerendra Rathor
You should use 'F' expression from django.db.models
So your expression would be like: 
ProductSale.objects.all().filter(date_expires__lt = now().date).exclude(
date_purchased__gt = F('date_expires'))

Which roughly translates to  
SELECT * FROM productsale WHERE date_expires < CURRENT_DATE AND NOT 
(date_purchased 
> date_expires)

in mysql. 

On Tuesday, 18 August 2015 06:26:56 UTC+5:30, Lee Hinde wrote:
>
> Given this model, I want to find all ProductSale objects that have expired 
> and where the Person doesn't have a later (unexpired) purchase of the same 
> product.
>
> class ProductSale(models.Model):
> product = models.ForeignKey(Product)
> person = models.ForeignKey(Person)
> ...
> date_expires = models.DateField(blank=True, db_index=True)
> 
>
> The closest I've gotten is in the shell where I get a values_list of 
> person and product for expired and unexpired and then compare the two 
> lists. That leaves me with a list of tuples, that (due to the size of the 
> list, I think) I can't use in a query.extra. 
>
> Any suggestions would be appreciated.
>
> (and sorry for the lame subject. I couldn't think of a way to be both 
> succinct and informative.)
>

-- 
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/26d0c805-54e5-4d9f-b3cb-07955cce9a66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query question

2015-08-17 Thread Dheerendra Rathor
You should use 'F' expression from django.db.models
So your expression would be like: 
ProductSale.objects.all().filter(date_expires__lg = 
now()).exclude(date_purchased__gt 
= F('date_expires'))



On Tuesday, 18 August 2015 06:26:56 UTC+5:30, Lee Hinde wrote:
>
> Given this model, I want to find all ProductSale objects that have expired 
> and where the Person doesn't have a later (unexpired) purchase of the same 
> product.
>
> class ProductSale(models.Model):
> product = models.ForeignKey(Product)
> person = models.ForeignKey(Person)
> ...
> date_expires = models.DateField(blank=True, db_index=True)
> 
>
> The closest I've gotten is in the shell where I get a values_list of 
> person and product for expired and unexpired and then compare the two 
> lists. That leaves me with a list of tuples, that (due to the size of the 
> list, I think) I can't use in a query.extra. 
>
> Any suggestions would be appreciated.
>
> (and sorry for the lame subject. I couldn't think of a way to be both 
> succinct and informative.)
>

-- 
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/daa1c2a5-1c8d-41f4-b4ca-73d0f6c70a1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Query question

2015-08-17 Thread Lee Hinde
Given this model, I want to find all ProductSale objects that have expired
and where the Person doesn't have a later (unexpired) purchase of the same
product.

class ProductSale(models.Model):
product = models.ForeignKey(Product)
person = models.ForeignKey(Person)
...
date_expires = models.DateField(blank=True, db_index=True)


The closest I've gotten is in the shell where I get a values_list of person
and product for expired and unexpired and then compare the two lists. That
leaves me with a list of tuples, that (due to the size of the list, I
think) I can't use in a query.extra.

Any suggestions would be appreciated.

(and sorry for the lame subject. I couldn't think of a way to be both
succinct and informative.)

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


Django foreign key in SlugRelatedField

2015-08-17 Thread Shekar Tippur
Hello,

I am trying to create a form that takes input needed for parent child 
tables. I am unable to create records via post call.
It is a simple parent child relationship. I want to be able to create the 
parent if it does not exist and create a child right after. I guess I am 
not able to understand this - 
http://www.django-rest-framework.org/api-guide/relations/. Appreciate any 
help.

The Error I see is :

{
"plumber": [
"Invalid value."
]}


Here is my views:


class PlumberPipelineList(generics.ListCreateAPIView):
queryset = PlumberPipeline.objects.all()
serializer_class = PlumberPipelineSerializer
def form_valid(self, form):
PlumberPipeline = form.save(commit=False)# dispatch(self, request, 
*args, **kwargs):
PlumberPipeline.plumber = self.request.plumber
return super(PlumberPipelineList, self).form_valid(form)


Serializer:

---


class CreatableSlugRelatedField(serializers.SlugRelatedField):
def to_internal_value(self, data):
try:
print ("In CreatableSlugRelatedField try" + data)
return self.get_queryset().get_or_create(**{self.slug_field: data})
except ObjectDoesNotExist:
print ("In CreatableSlugRelatedField exception")
self.fail('does_not_exist', slug_name=self.slug_field, 
value=smart_text(data))
except (TypeError, ValueError):
print ("In CreatableSlugRelatedField exception ")
#return self.get_queryset().get_or_create(**{self.slug_field: data})
self.fail('invalid')

class PlumberPipelineSerializer(serializers.ModelSerializer):

plumber = CreatableSlugRelatedField(
many=True,
slug_field='plumber',
queryset=PlumberPipeline.objects.all()
)

#plumber = serializers.SlugRelatedField(slug_field='plumber', many=True, 
queryset=Plumber.objects.all())
class Meta:
model = PlumberPipeline
fields = ('id','stage_title','plumber')
#fields = ('id', 'stage_title', 'plumber','streamProcessor','bus')

class PlumberSerializer(serializers.ModelSerializer):
#PlumberPipeline = PlumberPipelineSerializer(many=True)
'''
plumberPipelines = CreatableSlugRelatedField(
many=True,
slug_field='plumber',
queryset=PlumberPipeline.objects.all()
)
'''
class Meta:
model = Plumber
fields = ('id','title')


Model

--


class Plumber(models.Model):
plumber = models.CharField(max_length=500, blank=True, default='')
created = models.DateTimeField(auto_now_add=True)

class Meta:
managed = True
ordering = ('created','plumber')


class PlumberPipeline(models.Model):
stage_title = models.CharField(max_length=100, blank=False, default='')
plumber = models.ForeignKey(Plumber, related_name='plumberPipelines')
created = models.DateTimeField(auto_now_add=True)
class Meta:
managed = True

-- 
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/a7561dfc-8f0e-428b-86f4-d7600a280c7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: "Fake" multiple inheritance

2015-08-17 Thread James Schneider
Just making sure. Good luck!

-James
On Aug 17, 2015 1:25 PM, "Michael Herrmann"  wrote:

> Yes, of course you're right James, sorry. My classes are actually named
> differently and I was just trying to get the idea across.
> M
>
> On 17 August 2015 at 22:23, James Schneider 
> wrote:
>
>>
>>
>> Hi gst,
>>>
>>> Instead of
>>>
>>> class Hotel(Place):
>>> ...
>>>
>>> I ended up with
>>>
>>> class Hotel(object):
>>> place = models.OneToOneField(Place, primary_key=True)
>>>
>>> I used a OneToOneField instead of ForeignKey because there can only be
>>> one hotel in a Place.
>>>
>>>
>>>
>> Just to verify, you're not actually inheriting from (object), right?
>> You're using Hotel(models.Model), I hope?
>>
>> -James
>>
>> --
>> 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/26Qu9-wJ1gA/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/CA%2Be%2BciXYQN3%2BwFgm7U3BU17rm5Rw9x-Y7uQ4Whd8Hn%2BgkfjLgA%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> [image: Inline image 1]
>
> Michael Herrmann, MSc
> Alser Straße 18/26
> 1090 Wien
> Tel.: +43 699 11 65 16 40
> Email: mich...@herrmann.io
>
> --
> 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/CABrKpmCdDs46X33z_0p5wfLOs65TKaAJf4rfSjfyDjgL%2B%2BT1kA%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/CA%2Be%2BciX_qRPO2Rbu20sJ-eAqm3DUjRkRnp_v8uyBhtEGMR8vuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: "Fake" multiple inheritance

2015-08-17 Thread Michael Herrmann
Yes, of course you're right James, sorry. My classes are actually named
differently and I was just trying to get the idea across.
M

On 17 August 2015 at 22:23, James Schneider  wrote:

>
>
> Hi gst,
>>
>> Instead of
>>
>> class Hotel(Place):
>> ...
>>
>> I ended up with
>>
>> class Hotel(object):
>> place = models.OneToOneField(Place, primary_key=True)
>>
>> I used a OneToOneField instead of ForeignKey because there can only be
>> one hotel in a Place.
>>
>>
>>
> Just to verify, you're not actually inheriting from (object), right?
> You're using Hotel(models.Model), I hope?
>
> -James
>
> --
> 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/26Qu9-wJ1gA/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/CA%2Be%2BciXYQN3%2BwFgm7U3BU17rm5Rw9x-Y7uQ4Whd8Hn%2BgkfjLgA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
[image: Inline image 1]

Michael Herrmann, MSc
Alser Straße 18/26
1090 Wien
Tel.: +43 699 11 65 16 40
Email: mich...@herrmann.io

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


Re: Django: "Fake" multiple inheritance

2015-08-17 Thread James Schneider
Hi gst,
>
> Instead of
>
> class Hotel(Place):
> ...
>
> I ended up with
>
> class Hotel(object):
> place = models.OneToOneField(Place, primary_key=True)
>
> I used a OneToOneField instead of ForeignKey because there can only be one
> hotel in a Place.
>
>
>
Just to verify, you're not actually inheriting from (object), right? You're
using Hotel(models.Model), I hope?

-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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXYQN3%2BwFgm7U3BU17rm5Rw9x-Y7uQ4Whd8Hn%2BgkfjLgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


is there anybody who test this django mongodb engine ?

2015-08-17 Thread MahdiX
Hi folks
I just start learning and using mongoDB , it's looks like a really nice 
replacement for mysql.
I was searching for 3rd party for using Mongo with django and I ends up with 
django-mongodb-engine.
Has anybody test it?
I'm looking for personal experiences

-- 
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/e0402e40-f4cf-4738-9ba7-391ea1358ee4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Need help in Django Task

2015-08-17 Thread conticki
Task to be done in Django 

Table structure:

   - Movies
  - id
  - Title
  - Description
  - Featured image
  - Movie length (in minutes)
  - Movie release date
   
Example:

1 | Jurassic World | A movie about dinosaurs | 90 minutes | June 14 2015
2 | Kick | Salman Khan movie | 120 minutes | April 2014

   - Category
  - id
  - Type
  - Value
   

1 | Language | English
2 | Genre | Action
3 | Language | Hindi
4 | Genre | Comedy


   - Relationship
  - id
  - Taxonomy id
  - Movie id
   
Example:

1 | 1 | 1
2 | 1 | 2
3 | 2 | 3
4 | 2 | 4


Create a list view of movies with pagination after 10 movies. 
For pagination follow this approach. AJAX / Page Refresh  - your choice. 


   - Filter by language
   - Filter by Genre
   - Sort by Length
   - Sort by release date

Filter and sort need to work together. Filter and sort should continue to 
work when I change page. For example refer 
http://www.shortfilmwindow.com/movies/

Sort, filter and pagination need to be server side.

-- 
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/c31c4026-3efc-477e-b026-48e9e6364117%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: "Fake" multiple inheritance

2015-08-17 Thread Michael Herrmann
Hi gst,

Instead of

class Hotel(Place):
...

I ended up with

class Hotel(object):
place = models.OneToOneField(Place, primary_key=True)

I used a OneToOneField instead of ForeignKey because there can only be one
hotel in a Place.

M

On 16 August 2015 at 16:22, gst  wrote:

> Will you care share it?
> I found the question interresting..
> Thanks.
>
> --
> 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/26Qu9-wJ1gA/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/dd4e0868-7a69-4d46-87b3-a9b3e153f21d%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
[image: Inline image 1]

Michael Herrmann, MSc
Alser Straße 18/26
1090 Wien
Tel.: +43 699 11 65 16 40
Email: mich...@herrmann.io

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


the right way to generate my model/db_table

2015-08-17 Thread Naftali Michalowsky
Hello, 

I went through the tutorial with in mind to go through it again using it to 
set up my small app.

I am making a simple app where users can search a large set of strings and 
get a subset as a result. The only relevant search criteria is the first 
and last character of the string. 

So the table is static, meaning I'll fully populate it before app 
deployment and it will be read only, since the data set doesn't change ever.

A record will consist of a field containing the actual string, a field 
containing the first character and a field containing the last character, a 
field containing a json representation of the record (I believe postgres 
has funcitons to generate that for me) and some fields containing metadata 
concerning the string. The index will be a composite of the first and last 
character of the string.

In any case, I research and do as I go, so I need guidance as to the 
correct approach (as this is use case will be very common for me). 

I can either research creating this exact table in postgres an then use a 
django facility to generate the model 
(https://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb). 

Or I can research how to get Django to create this exact table and write 
the model accordingly and have Django create the table for me.  Bear in 
mind that I will in either case need to hit the table directly to 
pre-populate it (or so I believe, please let me know if there is a Django 
way to do that?).

I would think the former more natural but the docs seem to imply that it's 
for 'legacy' databases. 

What do you recommend as the appropriate approach to from scratch with. 

Thank you 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/1855101a-d913-4bb7-bfb8-c7965e5b4407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why should I care to use YAML with Django?

2015-08-17 Thread Bill Freeman
One interesting feature of YAML is the ability to have custom operators.
For example, with YAML used as a fixture, you might have an operator that
turns a hex string into a MongoDB ObjectId on read, or a date string into a
datetime object, meaning that you don't have to post process the data
read.  Other serializers can obviously be extended as well, but it seems to
have been well provided for in YAML (at least in  PyYAML).

On Sun, Aug 16, 2015 at 2:44 AM, James Schneider 
wrote:

> Probably for the same reasons you might use XML, CSV, or JSON; data
> exchange and serialization between systems. YAML is just another
> standardized way to encapsulate data structures so that they can be passed
> between systems or statically archived consistently.
>
> You could also not care at all if you have no data requirements on other
> systems that use YAML.
>
> Without more context, though, there isn't really a proper way to answer
> your question.
>
> -James
> On Aug 15, 2015 9:10 PM, "Joshua Ellis"  wrote:
>
>> What purpose does it have? What kind of problem am I bound to solve in
>> using it?
>>
>> --
>> 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/3fc97528-4f61-42b4-91c0-ef6f02e2e800%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/CA%2Be%2BciWrdFi_KuYgpb0EJug1Fw_PTWEZE34XF0%2BRgHAejfCoeA%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/CAB%2BAj0ucJHTojaO9LPWAjSwm8e%2Bk%2BzFDh_2LEnL%3D3qv8iDPtaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Architectural suggestions for (Django + API)

2015-08-17 Thread julio . lacerda
Hi Carl,
 

> I don't quite understand why the situation you describe requires 
> duplicating models files. Is the canonical data storage now in Project B 
> instead of Project A, and Project A gets the data via Project B's REST 
> API? In that case, why does Project A need those models anymore? 


Yes, that's it. I was thinking to maintain those models in Project A just 
because of the ModelForms, but now ... it seems a bad idea. In this case, I 
will need some refactor to use Form instead of ModelForm and after that I 
can't see any problem. You're right!

I will use this approach. Thank you very much!

Em segunda-feira, 17 de agosto de 2015 01:27:07 UTC-3, Carl Meyer escreveu:
>
> Hi Julio, 
>
> On 08/16/2015 04:59 PM, julio@m2agro.com.br  wrote: 
> > I created a project using Django (let's call this Project A) and now I 
> > decided to start a new one but this time it is an API using Django REST. 
> > So, for now I have to refactor Project A to consume data from API, but 
> > in order to do that I need to duplicate all my models files in both 
> > projects. The question is how can I avoid this? Is there another way to 
> > do that? 
>
> I don't quite understand why the situation you describe requires 
> duplicating models files. Is the canonical data storage now in Project B 
> instead of Project A, and Project A gets the data via Project B's REST 
> API? In that case, why does Project A need those models anymore? 
>
> > I see that /moving models /from Project A to API as something natural 
> > but to have an empty models file in Project A I need to change some 
> > concepts, for removing ModelForms and put all validation logic using 
> Form. 
>
> Well, yes, but it seems to me that those types of changes in the Project 
> A codebase will be required regardless, since it now wants to save the 
> data via a REST API, not to its own database. How does a ModelForm help 
> with that? 
>
> > How do you guys see this? Would you recommend something different? Is 
> > that a good idea? 
> > 
> >  1. Project A (Models) <---> API (same models??? How can I handle that?) 
> >  2. Project A (No models) <---> API (Models) 
>
> The latter. I don't understand how the first option would even work. 
>
> But if you _do_ want to share some models between two projects, for 
> whatever reason, you can do it the same way you'd share any other code: 
> put the models in a reusable app and install it in both projects. 
>
> Carl 
>
>
Em segunda-feira, 17 de agosto de 2015 01:27:07 UTC-3, Carl Meyer escreveu:
>
> Hi Julio, 
>
> On 08/16/2015 04:59 PM, julio@m2agro.com.br  wrote: 
> > I created a project using Django (let's call this Project A) and now I 
> > decided to start a new one but this time it is an API using Django REST. 
> > So, for now I have to refactor Project A to consume data from API, but 
> > in order to do that I need to duplicate all my models files in both 
> > projects. The question is how can I avoid this? Is there another way to 
> > do that? 
>
> I don't quite understand why the situation you describe requires 
> duplicating models files. Is the canonical data storage now in Project B 
> instead of Project A, and Project A gets the data via Project B's REST 
> API? In that case, why does Project A need those models anymore? 
>
> > I see that /moving models /from Project A to API as something natural 
> > but to have an empty models file in Project A I need to change some 
> > concepts, for removing ModelForms and put all validation logic using 
> Form. 
>
> Well, yes, but it seems to me that those types of changes in the Project 
> A codebase will be required regardless, since it now wants to save the 
> data via a REST API, not to its own database. How does a ModelForm help 
> with that? 
>
> > How do you guys see this? Would you recommend something different? Is 
> > that a good idea? 
> > 
> >  1. Project A (Models) <---> API (same models??? How can I handle that?) 
> >  2. Project A (No models) <---> API (Models) 
>
> The latter. I don't understand how the first option would even work. 
>
> But if you _do_ want to share some models between two projects, for 
> whatever reason, you can do it the same way you'd share any other code: 
> put the models in a reusable app and install it in both projects. 
>
> 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/0b09b2bb-e4d3-42a9-9eec-3314f5624089%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Architectural suggestions for (Django + API)

2015-08-17 Thread julio . lacerda
Hi James,

I'm going to build a separated instance to provide only REST services to be 
consumed by Project A. It's ok to use the same views to provide a REST 
interface in API but in this case I need to remove models from project A, 
right?

Thank you very much!

Em domingo, 16 de agosto de 2015 20:13:37 UTC-3, James Schneider escreveu:
>
> Are you adding REST functionality to an existing project? Or will you be 
> using a separate instance to provide only REST services and maintain two 
> different code bases?
>
> I believe you can use the django-rest-framework to utilize the same views 
> (literally) to provide a REST interface, so you may not need to rewrite or 
> copy anything, just add a few bits of code to make your views aware of 
> incoming REST requests, some URL additions, and serializers for your 
> models. 
>
> http://www.django-rest-framework.org/
>
> -James
> On Aug 16, 2015 3:59 PM,  wrote:
>
>> Hey guys,
>>
>> I have a question about an architectural issue and I would like to hear 
>> some suggestions about it.
>>
>> I created a project using Django (let's call this Project A) and now I 
>> decided to start a new one but this time it is an API using Django REST. 
>> So, for now I have to refactor Project A to consume data from API, but in 
>> order to do that I need to duplicate all my models files in both projects. 
>> The question is how can I avoid this? Is there another way to do that?
>>
>> I see that *moving models *from Project A to API as something natural 
>> but to have an empty models file in Project A I need to change some 
>> concepts, for removing ModelForms and put all validation logic using Form.
>>
>> How do you guys see this? Would you recommend something different? Is 
>> that a good idea?
>>
>>1. Project A (Models) <---> API (same models??? How can I handle 
>>that?)
>>2. Project A (No models) <---> API (Models)
>>
>> 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...@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/11d2f88e-a159-4e7b-903f-80d0f6e8e74a%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
Em domingo, 16 de agosto de 2015 20:13:37 UTC-3, James Schneider escreveu:
>
> Are you adding REST functionality to an existing project? Or will you be 
> using a separate instance to provide only REST services and maintain two 
> different code bases?
>
> I believe you can use the django-rest-framework to utilize the same views 
> (literally) to provide a REST interface, so you may not need to rewrite or 
> copy anything, just add a few bits of code to make your views aware of 
> incoming REST requests, some URL additions, and serializers for your 
> models. 
>
> http://www.django-rest-framework.org/
>
> -James
> On Aug 16, 2015 3:59 PM,  wrote:
>
>> Hey guys,
>>
>> I have a question about an architectural issue and I would like to hear 
>> some suggestions about it.
>>
>> I created a project using Django (let's call this Project A) and now I 
>> decided to start a new one but this time it is an API using Django REST. 
>> So, for now I have to refactor Project A to consume data from API, but in 
>> order to do that I need to duplicate all my models files in both projects. 
>> The question is how can I avoid this? Is there another way to do that?
>>
>> I see that *moving models *from Project A to API as something natural 
>> but to have an empty models file in Project A I need to change some 
>> concepts, for removing ModelForms and put all validation logic using Form.
>>
>> How do you guys see this? Would you recommend something different? Is 
>> that a good idea?
>>
>>1. Project A (Models) <---> API (same models??? How can I handle 
>>that?)
>>2. Project A (No models) <---> API (Models)
>>
>> 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...@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/11d2f88e-a159-4e7b-903f-80d0f6e8e74a%40googlegroups.com
>>  
>> 

Re: Is it possible to specifyc validate_min and validate_max on contrib.Admin formset ? (From Django's code, it seems not)

2015-08-17 Thread boitoletre
There is actually a workflow that feels inconsistent if we cannot easily 
enforce validate_min & _max on the Formset of the contrib.Admin.
Example:
a) For model A, attach an Inline for model B (B having a ForeingKey to A), 
with min_num < max_num
b) create an instance of A in the Admin interface: you will need to create 
between min_num and max_num B instance in the formset (because min_num and 
max_num are checked on creation)
c) edit the inserted A instance, you can delete as many B attached to it as 
you want, *allowing to save the result with number of B < min_num* (<- this 
is what validate_min would prevent)
d) now if you open the modified A instance for edition, you cannot save it 
anymore *even if you do not change anything* (because you have less B than 
min_num)


Le mercredi 12 août 2015 12:01:03 UTC+2, boito...@gmail.com a écrit :
>
> Hi,
>
>  I would need to enforce the max_num and min_num  attributes of formsets 
> on my admin pages at validation time.
> From the documentation and the source, it seems that validate_max and 
> validate_min would be the FormSet attributes that need to set to True for 
> that to happen.
>
> Yet, while investigating this issue, it seems to me that it is currently 
> not possible to forward them to FromSet classes used in the Admin site:
> 1) From InlineModelAdmin.get_formset() code 
> ,
>  
> it is not useful to set validate_* on the inline itself, as it would not be 
> forwarded to the inlineformset_factory() call on return.
> 2) From formset_factory() code 
> ,
>  
> it is not useful to set validate_* on the FormSet class itself, because it 
> would be overwritten by the argument provided to the factory function.
>
> Are you aware of a way to have the Admin instantiate FormSet classes with 
> valide_min and validate_max set to true ?
> If not, it seems to me it would be easy to allow it by extending the 
> defaults dictionary in 1), so I am curious if there is a rationale for not 
> allowing it, or if it is a simple oversight ?
>
> Thank you very much for reading,
>   Ad
>

-- 
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/9af8e744-1f38-4a20-a8a3-a654d882b7d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.