Annotate on related field

2016-07-12 Thread Ramashish Baranwal
Hi, I have the following model definitions: class Tag(models.Model): name = models.CharField(max_length=16) class Blog(models.Model): name = models.CharField(max_length=16) tags = models.ManyToManyField(Tag, blank=True) I want to select blogs with more than one tags. Here is what

Re: Tables with same schema

2009-05-01 Thread Ramashish Baranwal
> Plain ol' Python multiple inheritance should work. Just define the > fields you want in some class: > {{{ > class PersonMixin(object): >     first = models.CharField(max_length=16) >     last = models.CharField(max_length=16) > > class Person(models.Model, PersonMixin): >     pass > > class Pers

Re: Tables with same schema

2009-04-30 Thread Ramashish Baranwal
> > > I want to create several tables with same schema. This is to partition > > the data into different tables. Apart from having model classes with > > same definition, is there another way to do it? > > > Here is a trivial example that duplicates the class definition- > > > class Person(models.

Tables with same schema

2009-04-30 Thread Ramashish Baranwal
Hi, I want to create several tables with same schema. This is to partition the data into different tables. Apart from having model classes with same definition, is there another way to do it? Here is a trivial example that duplicates the class definition- class Person(models.Model): first =

Re: After sending HttpResponse

2009-03-17 Thread Ramashish Baranwal
> > I need to do some cleanup after sending a response to the client. That > > means I want to send response without returning a response object. > > Something like- > > > def handler(request): > >     # ... > >     resp = HttpResponse(data) > >     # send response in some way (?) > >     # clean

After sending HttpResponse

2009-03-17 Thread Ramashish Baranwal
Hi, I need to do some cleanup after sending a response to the client. That means I want to send response without returning a response object. Something like- def handler(request): # ... resp = HttpResponse(data) # send response in some way (?) # clean up, log, etc.. I know its u

Hierarchy on foreign key

2008-10-05 Thread Ramashish Baranwal
Hi, On admin change list, I want to group objects based on a foreign key. Is there a way to generate a hierarchy based on foreign/m2m key instead of date? Consider the following example- class Book(models.Model): # ... publisher = models.ForeignKey(Publisher) On Book's admin page, I wa

Re: automatically generated field in admin

2008-10-01 Thread Ramashish Baranwal
> > > I have a model in which a field should be generated automatically. So > > it shouldn't be shown in the admin add page. Also in the change page > > it should be shown but should be non-editable. As an example- > > Pending ticket 342, another way to do this is to make a custom admin > change_f

automatically generated field in admin

2008-10-01 Thread Ramashish Baranwal
Hi, I have a model in which a field should be generated automatically. So it shouldn't be shown in the admin add page. Also in the change page it should be shown but should be non-editable. As an example- class Student(models.Model): first = models.CharField(max_length=64) last = models.

Admin and ManyToManyField

2007-08-02 Thread Ramashish Baranwal
Hi, I have a model that has a ManyToManyField. When I try to add/edit an object of this model in admin, it says that the ManyToManyField is required i.e. I can not leave it out. While, from the shell I can easily create an object without adding anything in the ManyToManyField. The same happens fo

Binary data in CharField.

2007-06-24 Thread Ramashish Baranwal
Hi, Apologies if its mentioned in the documentation. I would like to know whether I can put binary data in a CharField? Thanks, Ram --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to

Re: Comparing dates..

2007-06-20 Thread Ramashish Baranwal
On Jun 20, 4:36 am, oggie rob <[EMAIL PROTECTED]> wrote: > I could be a bit more pythonic: > > >>> from django.db.models.query import QOr > >>> ql = [Q(birthdate__day=(startdate + timedelta(days=x)).day) & > >>> Q(birthdate__month=(startdate + timedelta(days=x)).month) for x in > >>> range(7)] >

Re: How to setup Django on Apache with correct rights and owners

2007-06-20 Thread Ramashish Baranwal
On Jun 20, 8:29 pm, Pythoni <[EMAIL PROTECTED]> wrote: > I use Django with Apache and it runs great. > I have root access to the server. > But still I am not sure what are the best raccess rights for : > settings.py > for files in > models and views directories and for directories themselves. > W

Comparing dates..

2007-06-19 Thread Ramashish Baranwal
Hi, I want to compare dates in my db while ignoring the year field. Lets say I have a birthday field and want to find upcoming birthdays in the next one week. How can I achieve this? If I try- last_date = datetime.now().date() + timedelta(days=7) users = User.objects.filter(birthday__day__lte =

Case insensitive urls

2007-06-01 Thread Ramashish Baranwal
Hi, I would like to make urls of my site case-insensitive. As I understand, by default the url matching is case-sensitive. Is there a way to specify in my urls.py that I want a case-insensitive match? Thanks, Ram --~--~-~--~~~---~--~~ You received this message b

Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal
> On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > > > The session is a model in Django - so you can delete it like any other - > > > x=request.session > > x.delete() > > > There's also the daily_cleanup.py script included with Django that > > just goes straight to the > > database

Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal
On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > The session is a model in Django - so you can delete it like any other - > > x=request.session > x.delete() > > There's also the daily_cleanup.py script included with Django that > just goes straight to the > database:http://code.dja

Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal
On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > The session is a model in Django - so you can delete it like any other - > > x=request.session > x.delete() > > There's also the daily_cleanup.py script included with Django that > just goes straight to the > database:http://code.dja

Re: How to delete a session

2007-05-23 Thread Ramashish Baranwal
On May 23, 10:18 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > The session is a model in Django - so you can delete it like any other - > > x=request.session > x.delete() > > There's also the daily_cleanup.py script included with Django that > just goes straight to the > database:http://code.dja

How to delete a session

2007-05-23 Thread Ramashish Baranwal
Hi, How can I delete the session of a request? The docs speak about using session as a dict and setting and removing specific keys on that, but I want to remove the session itself, something like del request.session Any ideas? Thanks in advance, Ram --~--~-~--~~~--

Re: Serialization with file output

2007-05-22 Thread Ramashish Baranwal
Malcolm Tredinnick wrote: > > I am trying to serialize some model data with the output going to a > > file. I am doing it the way its suggested in the documentation. > > > > XMLSerializer = serializers.get_serializer("xml") > > xml_serializer = XMLSerializer() > > out = open("file.xml", "w") > > x

Serialization with file output

2007-05-22 Thread Ramashish Baranwal
Hi, I am trying to serialize some model data with the output going to a file. I am doing it the way its suggested in the documentation. XMLSerializer = serializers.get_serializer("xml") xml_serializer = XMLSerializer() out = open("file.xml", "w") xml_serializer.serialize(SomeModel.objects.all(),

Re: Cannot resolve keyword into field

2007-04-24 Thread Ramashish Baranwal
On Apr 24, 1:45 am, "Jason McVetta" <[EMAIL PROTECTED]> wrote: > > TypeError: Cannot resolve keyword 'book' into field > > This is a long-standing, well-known bug that apparently no one (including > me) knows how to fix. > > Any time one defines a ManyToMany relationship, then calls all() on tha

Re: Cannot resolve keyword into field

2007-04-24 Thread Ramashish Baranwal
On Apr 22, 7:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Can you post the exact code throwing the error, and copy paste your > exact model code related to the error? The code is exactly the same as I wrote in my OP. # models.py from django.db import models # Create your models here

Re: Cannot resolve keyword into field

2007-04-21 Thread Ramashish Baranwal
On Apr 22, 3:13 am, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > Hi, > > I using a script to fetch some database records. However, when it > encounters a ManyToManyField it gives the following error- > > TypeError: Cannot resolve keyword 'book' into fiel

Cannot resolve keyword into field

2007-04-21 Thread Ramashish Baranwal
Hi, I using a script to fetch some database records. However, when it encounters a ManyToManyField it gives the following error- TypeError: Cannot resolve keyword 'book' into field My models.py looks like this- from django.db import models # Create your models here. class Author(models.Model)

Re: Accessing model fields automatically..

2007-03-31 Thread Ramashish Baranwal
On Mar 31, 9:13 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On 3/31/07,RamashishBaranwal <[EMAIL PROTECTED]> wrote: > > > I am trying to export a model's data to XML. To do this I'm using the > > model class's _meta.fields. However it doesn't list ManyToManyField > > objects. How can I

Re: Accessing model fields automatically..

2007-03-31 Thread Ramashish Baranwal
On Mar 31, 10:36 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Sat, 2007-03-31 at 05:27 +,RamashishBaranwal wrote: > > Hi, > > > I am trying to export a model's data to XML. To do this I'm using the > > model class's _meta.fields. However it doesn't list ManyToManyField > > objects. H

Accessing model fields automatically..

2007-03-30 Thread Ramashish Baranwal
Hi, I am trying to export a model's data to XML. To do this I'm using the model class's _meta.fields. However it doesn't list ManyToManyField objects. How can I get those? My code looks something like this- # returns data of inst in a dict def get_data(inst): data = {} for field in inst._me

Query regarding Schema evolution branch.

2007-02-19 Thread Ramashish Baranwal
Hi, I am writing an app where I will occasionally need to change my db schema. I am not an SQL expert, and would like to confine myself to python and django db APIs if possible (don't want to go through raw SQL or db engine specific code). After some googling I found django's schema evolution bra

Re: Restricting q QuerySet based on ManyToManyField

2007-01-29 Thread Ramashish Baranwal
> Ram- > > I believe that > > User.objects.filter(related__name__starts_with='A') > > would get you what you're looking for, per the example at > starting > with block "# We can perform kwarg queries across m2m relationships". Tha

Restricting q QuerySet based on ManyToManyField

2007-01-28 Thread Ramashish Baranwal
Hi, I would like to restrict a QuerySet based on its ManyToManyField. In particular, based on what the ManyToManyField contains. Consider this trivial and a bit non-sense example- class User: name = models.CharField(maxlength=24) related = models.ManyToManyField('self', symmetric=False

Re: Restricting q QuerySet based on ManyToManyField

2007-01-28 Thread Ramashish Baranwal
On 1/28/07, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > Hi, > > I would like to restrict a QuerySet based on its ManyToManyField. In > particular, based on what the ManyToManyField contains. Consider this > trivial and a bit non-sense example- > > class User: &g