Re: Updating a model instance with extra checks.

2012-08-21 Thread Sebastien Flory
That was my idea too, but using this way, the pre_save / post_save signals 
wont be triggered.
It seems strange to me to be using the objects manager instead of the model 
instance directly, no?

Seb

Le mardi 21 août 2012 02:11:42 UTC+2, Thomas Orozco a écrit :
>
> As a followup to the suggestion of MyModel.objects.filter(money__gte = 
> value, pk = self.pk).update(F...)
>
> Here's an example:
>
> We have testapp/models.py:
>
> from django.db import models
> class TestModel(models.Model):
> balance =  models.IntegerField()
>
>
> >>> from django.db.models import F
> >>> TestModel.objects.create(balance = 5) #Pk will be 1 I just create one. 
> >>> import logging
> >>> l = logging.getLogger('django.db.backends')
> >>> l.setLevel(logging.DEBUG)
> >>> l.addHandler(logging.StreamHandler())
> >>> TestModel.objects.filter(balance__gte = 4, pk = 1).update(balance = 
> F('balance') - 4)
> (0.001) UPDATE "testapp_testmodel" SET "balance" = 
> "testapp_testmodel"."balance" - 4 WHERE ("testapp_testmodel"."balance" >= 4 
>  AND "testapp_testmodel"."id" = 1 ); args=(4, 4, 1)
> 1
> >>> TestModel.objects.filter(balance__gte = 4, pk = 1).update(balance = 
> F('balance') - 4)
> (0.000) UPDATE "testapp_testmodel" SET "balance" = 
> "testapp_testmodel"."balance" - 4 WHERE ("testapp_testmodel"."balance" >= 4 
>  AND "testapp_testmodel"."id" = 1 ); args=(4, 4, 1)
> 0
>
>
>
> *So this seems to generate a single SQL statement.*
> *
> *
> *I'm not totally familiar with database administration though, so as** Melvyn 
> rightly pointed out, it's always better if you can get the extra security 
> of having an SQL constraint into your dabatase and wrap your queries in a 
> transaction (as you'll probably be adding a line to the statement if the 
> withdrawal succeeds).*
> *
> *
>
> 2012/8/20 Thomas Orozco >
>
>> A few suggestions :
>>
>> Circumvent the problem with smarter design: don't store the money on the 
>> object, make the user's money the sum of all their transactions (credit - 
>> debit). 
>> You get lesser performance, but you also get history! 
>>
>> Maybe you could try (not sure about that): 
>>
>> MyModel.objects.filter(money__gte = value, pk = self.pk).update(F...) 
>>
>> and inspect the return value (number of updated rows!). 
>> Now, you'd need to make sure django does that in a single statement. 
>>
>> If that doesn't work, I think update is the way to go anyway, but it 
>> might get a bit messy. 
>>
>> F... is an F object whose syntax I don't have off the top of my head. 
>> Le 20 août 2012 18:54, "Sebastien Flory" > 
>> a écrit :
>>
>> Hi everyone,
>>>
>>> I'm looking for the proper django way to do an update of an attribute on 
>>> my model instance, but only if the attribute current value is checked 
>>> agains't a condition, in an atomic way, something like this:
>>>
>>> def use_money(self, value):
>>>   begin_transaction()
>>>   real_money = F('money')
>>>   if real_money >= value:
>>> self.money = F('money') - value
>>>  self.save()
>>>   end_transaction()
>>>
>>> I want to make sure that I avoid race condition so money never goes 
>>> below 0.
>>>
>>> Can you help me out?
>>>
>>> Thanks,
>>>
>>> Sebastien
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msg/django-users/-/hr1fBuAcX3kJ.
>>> To post to this group, send email to django...@googlegroups.com
>>> .
>>> To unsubscribe from this group, send email to 
>>> django-users...@googlegroups.com .
>>> For more options, visit this group at 
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/x8CZ3-F30PsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



issues with file upload

2012-08-21 Thread 软刀

I now  work with mongoengine, mongoForm
and set this in setting.py
DEFAULT_FILE_STORAGE = 'mongoengine.django.storage.GridFSStorage'

I need to upload a picture, and I wrote a form like this:

from django.forms import ImageField

  from mongoforms import MongoForm
  from documents import UserProfile
  
  class ProfileForm(MongoForm):
  photo = ImageField()
  class Meta:
  document = UserProfile
  exclude = ('user', 'photo')

but I get a Invalid Image Error when I submit a picture( how ever, it's ok 
when I use PIL.Image.open(photo).verify() )
I review the code, and found the exception was raise on 
django.forms.fields.ImageField.to_python method
code snippet for to_python method:
  def to_python(self, data):
   
   if hasattr(data, 'temporary_file_path'):
  file = data.temporary_file_path()
   
   try:
Image.open(file).verify()
except ImportError:
raise
except Exception: # Python Imaging Library doesn't recognize it as 
an image
raise ValidationError(self.error_messages['invalid_image'])
...

   well, I don't know well to set temporary_file_path and how to 
storage it with mongoengine.django.storage.GridFSStorage


# this was snippet for class ImageField
def to_python(self, data):
"""
Checks that the file-upload field data contains a valid image (GIF, 
JPG,
PNG, possibly others -- whatever the Python Imaging Library 
supports).
"""
f = super(ImageField, self).to_python(data)
if f is None:
return None

# Try to import PIL in either of the two ways it can end up 
installed.
try:
from PIL import Image
except ImportError:
import Image

# We need to get a file object for PIL. We might have a path or we 
might
# have to read the data into memory.
if hasattr(data, 'temporary_file_path'):
file = data.temporary_file_path()
else:
if hasattr(data, 'read'):
file = StringIO(data.read())
else:
file = StringIO(data['content'])

try:
# load() could spot a truncated JPEG, but it loads the entire
# image in memory, which is a DoS vector. See #3848 and #18520.
# verify() must be called immediately after the constructor.
Image.open(file).verify()
except ImportError:
# Under PyPy, it is possible to import PIL. However, the 
underlying
# _imaging C module isn't available, so an ImportError will be
# raised. Catch and re-raise.
raise
except Exception: # Python Imaging Library doesn't recognize it as 
an image
raise ValidationError(self.error_messages['invalid_image'])
if hasattr(f, 'seek') and callable(f.seek):
f.seek(0)
return f

 

 
this was exception stack

Environment:


Request Method: POST
Request URL: http://localhost:8000/accounts/profile/

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'registration',
 'bussiness',
 'accounts',
 'debug_toolbar']
Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']


Traceback:
File 
"/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/core/handlers/base.py"
 
in get_response
  111. response = callback(request, *callback_args, 
**callback_kwargs)
File 
"/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py"
 
in _wrapped_view
  20. return view_func(request, *args, **kwargs)
File "/home/yan/git/haoyoubang/accounts/views.py" in profile
  31. processFile(request.FILES['photo'])
File "/home/yan/git/haoyoubang/accounts/views.py" in processFile
  21. s = f.clean(photo)
File 
"/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/forms/fields.py"
 
in clean
  535. return super(FileField, self).clean(data)
File 
"/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/forms/fields.py"
 
in clean
  153. value = self.to_python(value)
File 
"/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/forms/fields.py"
 
in to_python
  593. raise 
ValidationError(self.error_messages['invalid_image'])

Exception Type: ValidationError at /accounts/profile/
Exception Value: 
[u'\u8bf7\u4e0a\u4f20\u4e00\u5f20\u6709\u6548\u7684\u56fe\u

Re: django + TinyMce

2012-08-21 Thread Владислав Иванов
Guys, Thanks!! I have converted my class and I did it!  But displays the 
text along with the styles for some reason:

Дипломная работа 
была выполнена в 2010 г. специалистами Учебного центра Рефермейкер по 
индивидуальному заказу.Общий объем дипломной работы на тему «Женская 
преступность» — 78 стр., количество ссылок — 
88.

My admin.py (I think I need to put the *self*, but do not know where

class TinyMCEAdmin(admin.ModelAdmin):

list_display = ('tema', 'predmet', 'tip', 'pub_date')

list_filter = ['predmet']

search_fields = ['tema']


 def formfield_for_dbfield(self, db_field, **kwargs):

if db_field.name in ('anounce', 'soderz', 'istochnik'):

return db_field.formfield(widget=TinyMCE(

attrs={'cols': 130, 'rows': 30},


 ))

return super(TinyMCEAdmin, self).formfield_for_dbfield(db_field, **kwargs)



admin.site.register(Raboty, TinyMCEAdmin)

admin.site.register(Tipes)

admin.site.register(Disciplina)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/BlG7pa-pC3IJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



new to django

2012-08-21 Thread maha
Hi,I am new to django. Right now I am going through the tutorial. I am 
stuck on the creating poll application. 

*Here are the settings.py ,* 

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
   'poll',
)

*here are the models.py*

from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField()

*here are the urls.py,*

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysitee.views.home', name='home'),
# url(r'^mysitee/', include('mysitee.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
 i got struck, after i was running this command *python manage.py shell,* (i.e) 
while exploring the database in python shell.

do u need to show any other code, which i used.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/V262IvOrL9kJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: new to django

2012-08-21 Thread Anoop Thomas Mathew
What is the error you are getting?

atm
___
Life is short, Live it hard.




On 21 August 2012 12:57, maha  wrote:

> Hi,I am new to django. Right now I am going through the tutorial. I am
> stuck on the creating poll application.
>
> *Here are the settings.py ,*
>
> INSTALLED_APPS = (
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> # Uncomment the next line to enable the admin:
> 'django.contrib.admin',
> # Uncomment the next line to enable admin documentation:
> # 'django.contrib.admindocs',
>'poll',
> )
>
> *here are the models.py*
>
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField()
>
> *here are the urls.py,*
>
> from django.conf.urls import patterns, include, url
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
> # Examples:
> # url(r'^$', 'mysitee.views.home', name='home'),
> # url(r'^mysitee/', include('mysitee.foo.urls')),
>
> # Uncomment the admin/doc line below to enable admin documentation:
> url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
> # Uncomment the next line to enable the admin:
> # url(r'^admin/', include(admin.site.urls)),
> )
>  i got struck, after i was running this command *python manage.py shell,* 
> (i.e)
> while exploring the database in python shell.
>
> do u need to show any other code, which i used.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/V262IvOrL9kJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: new to django

2012-08-21 Thread Dhilip S
Hello,

Got struct means you got any error or don't know what to do after that
Just follow the tutorial, read out each and every line in the document.
>
>
>
On Tue, Aug 21, 2012 at 12:57 PM, maha  wrote:

> Hi,I am new to django. Right now I am going through the tutorial. I am
> stuck on the creating poll application.
>
> *Here are the settings.py ,*
>
> INSTALLED_APPS = (
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> # Uncomment the next line to enable the admin:
> 'django.contrib.admin',
> # Uncomment the next line to enable admin documentation:
> # 'django.contrib.admindocs',
>'poll',
> )
>
> *here are the models.py*
>
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField()
>
> *here are the urls.py,*
>
> from django.conf.urls import patterns, include, url
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
> # Examples:
> # url(r'^$', 'mysitee.views.home', name='home'),
> # url(r'^mysitee/', include('mysitee.foo.urls')),
>
> # Uncomment the admin/doc line below to enable admin documentation:
> url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
> # Uncomment the next line to enable the admin:
> # url(r'^admin/', include(admin.site.urls)),
> )
>  i got struck, after i was running this command *python manage.py shell,* 
> (i.e)
> while exploring the database in python shell.
>
> do u need to show any other code, which i used.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/V262IvOrL9kJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



--Dhilip.S

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: new to django

2012-08-21 Thread Joris


On Tuesday, August 21, 2012 1:08:04 PM UTC+2, Dhilip wrote:
>
> Hello,
>
> Got struct means you got any error or don't know what to do after that 
> Just follow the tutorial, read out each and every line in the document. 
> >
>

also make sure you are following the tutorial related to the Django version 
you are using! Google tends to redirect you to the /dev/ version of the 
tutorial with is incompatible with django 1.3

jb



 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Z6C1FHT3a0cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: new to django

2012-08-21 Thread Melvyn Sopacua
On 21-8-2012 9:27, maha wrote:

>  i got stuck, after i was running this command *python manage.py shell,* 
> (i.e) 
> while exploring the database in python shell.

Did you forget the `python manage.py syncdb` part?

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Questions Tags Users Badges Unanswered Ask Question

2012-08-21 Thread boddireddy purnachander
Technologies used Python Django framework (from https://www.djangoproject.com/) 
HTML table filter sort (from http://tablefilter.free.fr/dwn.php)

While all other accompanied '.css' and '.js' files in /static/css and 
/static/js work, only 'tfAdapter.sortabletable.js' does not.

No error is seen (in logs too) when I run the server. But when I try to open 
the html files which include 'tfAdapter.sortabletable.js' file it shows '404 
file not found'.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/dyjutUdyxv4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ManyToManyField errors.

2012-08-21 Thread Nicolas Emiliani
On Mon, Aug 20, 2012 at 4:31 PM, MN TS  wrote:

> Hello
> I'm new in Django using 1.4version.
> So got some error.
>
> 'myapp.models.AdversiteImages'> has no ForeignKey to  'myapp.models.Adversite'>
>
> *
> MODEL*
>
> class AdversiteImages(models.Model):
> image = models.FileField(u'Photo' ,
> upload_to='adversiteimage/%Y/%m/%d', null=True, blank=True)
>
> class Adversite(models.Model):
> category = models.ForeignKey(AdversiteCategory, verbose_name=u'Зарын
> ангилал', related_name='adv_cat', blank=True, null=True)
> image_many = models.ManyToManyField(AdversiteImages,
> verbose_name=u'Photos',related_name="photos")
> title = models.CharField(u'Title', max_length=128)
> body = models.TextField(u'Description')
>
>
> *ADMIN*
>
> class
> AdversiteImagesInline(admin.TabularInline):
>
> model = Adversite.image_many.through
> extra = 1
>
> class AdversiteAdmin(admin.StackedInline):
> fieldsets = ((u'Ерөнхий',
> {'fields':('category','title','body','code')}),
>  (u'Тайлбар',
> {'fields':('price','phone','email','image1','image2','image3','image4','image5'
>
> ,'is_active','is_special','is_premium','start_at','finish_at')}))
> list_display = ('category','title','code','is_active','is_special')
> search_fields = ('category','title','code','is_active')
> model = Adversite.image_many.through
>
> Please help me.
>
>

Well, this is just a guess, but you are setting the model in the form as
the through attribute of an M2M relationship
and that might the problem, have you tried explicitly declaring the through
parameter in the M2M like it says here?

https://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany




>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



From Django 1.1 to Django 1.3.1 - Goes Very Slow

2012-08-21 Thread ydjango

 I have typical LAMP stack application. I use ORM very heavily. I recently 
migrated from django 1.1 to django 1.3.1.
Application has become very slow even though I have doubled the hardware.

Two major changes have been:
1) I have moved database (mysql) to different server
2) I have migrated django from 1.1 to 1.3.1

Any clues on what I should look at?
Any Django 1.3.1 specific settings I should look at?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/cEMDRRQC6LgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: From Django 1.1 to Django 1.3.1 - Goes Very Slow

2012-08-21 Thread Paul Backhouse
On Tue, 2012-08-21 at 07:30 -0700, ydjango wrote:
> 
>  I have typical LAMP stack application. I use ORM very heavily. I
> recently migrated from django 1.1 to django 1.3.1.
> Application has become very slow even though I have doubled the
> hardware.
> 
> Two major changes have been:
> 1) I have moved database (mysql) to different server
> 2) I have migrated django from 1.1 to 1.3.1
> 
> Any clues on what I should look at?
> Any Django 1.3.1 specific settings I should look at?

I think there are some browser tools that you could look at installing.
Firebug will tell you details about time to fetch files. I think there's
yslow too. Django debug toolbar will also tell you what queries are
being made and how long they take.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Updating a model instance with extra checks.

2012-08-21 Thread Kurtis Mullins
I remember running into similar situations in a different domain (collision
detection in physics engines). It was a pain in the butt :) I'd say first,
figure out what you want to do if the process does reach a point where
there isn't sufficient funds to perform the transaction. Then take multiple
steps to catch that state. Finally, implement it in a way that will leave
no side effects.

Possibly using a queue may be good for this. Let the user perform an action
which will attempt to use/move the funds. Then, actually try to perform the
operation behind the scenes. Finally, update the user's information so they
can see the change or any errors that occurred. This should
(hypothetically, assuming you only have one queue per user or account) make
sure that the transactions are performed in order and should also eliminate
race conditions. This would be similar in implementation to how many bank
web-sites let you transfer funds between accounts but it's typically not an
update you see immediately.

On Tue, Aug 21, 2012 at 4:18 AM, Sebastien Flory  wrote:

> That was my idea too, but using this way, the pre_save / post_save signals
> wont be triggered.
> It seems strange to me to be using the objects manager instead of the
> model instance directly, no?
>
> Seb
>
> Le mardi 21 août 2012 02:11:42 UTC+2, Thomas Orozco a écrit :
>>
>> As a followup to the suggestion of MyModel.objects.filter(**money__gte =
>> value, pk = self.pk).update(F...)
>>
>> Here's an example:
>>
>> We have testapp/models.py:
>>
>> from django.db import models
>> class TestModel(models.Model):
>> balance =  models.IntegerField()
>>
>>
>> >>> from django.db.models import F
>> >>> TestModel.objects.create(**balance = 5) #Pk will be 1 I just create
>> one.
>> >>> import logging
>> >>> l = logging.getLogger('django.db.**backends')
>> >>> l.setLevel(logging.DEBUG)
>> >>> l.addHandler(logging.**StreamHandler())
>> >>> TestModel.objects.filter(**balance__gte = 4, pk = 1).update(balance
>> = F('balance') - 4)
>> (0.001) UPDATE "testapp_testmodel" SET "balance" =
>> "testapp_testmodel"."balance" - 4 WHERE ("testapp_testmodel"."balance" >= 4
>>  AND "testapp_testmodel"."id" = 1 ); args=(4, 4, 1)
>> 1
>> >>> TestModel.objects.filter(**balance__gte = 4, pk = 1).update(balance
>> = F('balance') - 4)
>> (0.000) UPDATE "testapp_testmodel" SET "balance" =
>> "testapp_testmodel"."balance" - 4 WHERE ("testapp_testmodel"."balance" >= 4
>>  AND "testapp_testmodel"."id" = 1 ); args=(4, 4, 1)
>> 0
>>
>>
>>
>> *So this seems to generate a single SQL statement.*
>> *
>> *
>> *I'm not totally familiar with database administration though, so as** Melvyn
>> rightly pointed out, it's always better if you can get the extra security
>> of having an SQL constraint into your dabatase and wrap your queries in a
>> transaction (as you'll probably be adding a line to the statement if the
>> withdrawal succeeds).*
>> *
>> *
>>
>> 2012/8/20 Thomas Orozco 
>>
>>> A few suggestions :
>>>
>>> Circumvent the problem with smarter design: don't store the money on the
>>> object, make the user's money the sum of all their transactions (credit -
>>> debit).
>>> You get lesser performance, but you also get history!
>>>
>>> Maybe you could try (not sure about that):
>>>
>>> MyModel.objects.filter(money__**gte = value, pk = self.pk).update(F...)
>>>
>>> and inspect the return value (number of updated rows!).
>>> Now, you'd need to make sure django does that in a single statement.
>>>
>>> If that doesn't work, I think update is the way to go anyway, but it
>>> might get a bit messy.
>>>
>>> F... is an F object whose syntax I don't have off the top of my head.
>>> Le 20 août 2012 18:54, "Sebastien Flory"  a écrit :
>>>
>>> Hi everyone,

 I'm looking for the proper django way to do an update of an attribute
 on my model instance, but only if the attribute current value is checked
 agains't a condition, in an atomic way, something like this:

 def use_money(self, value):
   begin_transaction()
   real_money = F('money')
   if real_money >= value:
 self.money = F('money') - value
  self.save()
   end_transaction()

 I want to make sure that I avoid race condition so money never goes
 below 0.

 Can you help me out?

 Thanks,

 Sebastien

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To view this discussion on the web visit https://groups.google.com/d/**
 msg/django-users/-/**hr1fBuAcX3kJ
 .
 To post to this group, send email to django...@googlegroups.com.
 To unsubscribe from this group, send email to django-users...@**
 googlegroups.com.

 For more options, visit this group at http://groups.google.com/**
 group/django-users?hl=en
 .

>>>
>>  --
> You received this message b

Re: Questions Tags Users Badges Unanswered Ask Question

2012-08-21 Thread Kurtis Mullins
Is your tfAdapter.sortabletable.js file in one of your static directories?
If so, are you using the proper URL to access it? For example, . If so, what
do you see when you "View Source" through your browser on that page? If you
click on the javascript link from the "View Source", does it still show up
as a 404 error?

On Tue, Aug 21, 2012 at 7:43 AM, boddireddy purnachander <
bpurnachan...@gmail.com> wrote:

> Technologies used Python Django framework (from
> https://www.djangoproject.com/) HTML table filter sort (from
> http://tablefilter.free.fr/dwn.php)
>
> While all other accompanied '.css' and '.js' files in /static/css and
> /static/js work, only 'tfAdapter.sortabletable.js' does not.
>
> No error is seen (in logs too) when I run the server. But when I try to
> open the html files which include 'tfAdapter.sortabletable.js' file it
> shows '404 file not found'.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/dyjutUdyxv4J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Having LiveServerTestCase use same database as tests

2012-08-21 Thread Phil Gyford
I'm writing integration tests using LiveServerTestCase/Selenium in
v1.4.1. By default the process that's started by LiveServerTestCase
uses a different database to the test database used by the tests. This
is a pain because I can't use factories (I'm using FactoryBoy at the
moment) to create data to then test in the browser.

Is there a way I can get LiveServerTestCase using the same database as
the tests themselves?

Thanks,
Phil

-- 
http://www.gyford.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Updating a model instance with extra checks.

2012-08-21 Thread Thomas Orozco
I think  you could always send the signals yourself.

Wrap that along in a model method, and I don't see any issue with using the
manager!
Le 21 août 2012 10:18, "Sebastien Flory"  a écrit :

> That was my idea too, but using this way, the pre_save / post_save signals
> wont be triggered.
> It seems strange to me to be using the objects manager instead of the
> model instance directly, no?
>
> Seb
>
> Le mardi 21 août 2012 02:11:42 UTC+2, Thomas Orozco a écrit :
>>
>> As a followup to the suggestion of MyModel.objects.filter(**money__gte =
>> value, pk = self.pk).update(F...)
>>
>> Here's an example:
>>
>> We have testapp/models.py:
>>
>> from django.db import models
>> class TestModel(models.Model):
>> balance =  models.IntegerField()
>>
>>
>> >>> from django.db.models import F
>> >>> TestModel.objects.create(**balance = 5) #Pk will be 1 I just create
>> one.
>> >>> import logging
>> >>> l = logging.getLogger('django.db.**backends')
>> >>> l.setLevel(logging.DEBUG)
>> >>> l.addHandler(logging.**StreamHandler())
>> >>> TestModel.objects.filter(**balance__gte = 4, pk = 1).update(balance
>> = F('balance') - 4)
>> (0.001) UPDATE "testapp_testmodel" SET "balance" =
>> "testapp_testmodel"."balance" - 4 WHERE ("testapp_testmodel"."balance" >= 4
>>  AND "testapp_testmodel"."id" = 1 ); args=(4, 4, 1)
>> 1
>> >>> TestModel.objects.filter(**balance__gte = 4, pk = 1).update(balance
>> = F('balance') - 4)
>> (0.000) UPDATE "testapp_testmodel" SET "balance" =
>> "testapp_testmodel"."balance" - 4 WHERE ("testapp_testmodel"."balance" >= 4
>>  AND "testapp_testmodel"."id" = 1 ); args=(4, 4, 1)
>> 0
>>
>>
>>
>> *So this seems to generate a single SQL statement.*
>> *
>> *
>> *I'm not totally familiar with database administration though, so as** Melvyn
>> rightly pointed out, it's always better if you can get the extra security
>> of having an SQL constraint into your dabatase and wrap your queries in a
>> transaction (as you'll probably be adding a line to the statement if the
>> withdrawal succeeds).*
>> *
>> *
>>
>> 2012/8/20 Thomas Orozco 
>>
>>> A few suggestions :
>>>
>>> Circumvent the problem with smarter design: don't store the money on the
>>> object, make the user's money the sum of all their transactions (credit -
>>> debit).
>>> You get lesser performance, but you also get history!
>>>
>>> Maybe you could try (not sure about that):
>>>
>>> MyModel.objects.filter(money__**gte = value, pk = self.pk).update(F...)
>>>
>>> and inspect the return value (number of updated rows!).
>>> Now, you'd need to make sure django does that in a single statement.
>>>
>>> If that doesn't work, I think update is the way to go anyway, but it
>>> might get a bit messy.
>>>
>>> F... is an F object whose syntax I don't have off the top of my head.
>>> Le 20 août 2012 18:54, "Sebastien Flory"  a écrit :
>>>
>>> Hi everyone,

 I'm looking for the proper django way to do an update of an attribute
 on my model instance, but only if the attribute current value is checked
 agains't a condition, in an atomic way, something like this:

 def use_money(self, value):
   begin_transaction()
   real_money = F('money')
   if real_money >= value:
 self.money = F('money') - value
  self.save()
   end_transaction()

 I want to make sure that I avoid race condition so money never goes
 below 0.

 Can you help me out?

 Thanks,

 Sebastien

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To view this discussion on the web visit https://groups.google.com/d/**
 msg/django-users/-/**hr1fBuAcX3kJ
 .
 To post to this group, send email to django...@googlegroups.com.
 To unsubscribe from this group, send email to django-users...@**
 googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/django-users?hl=en
 .

>>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/x8CZ3-F30PsJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: From Django 1.1 to Django 1.3.1 - Goes Very Slow

2012-08-21 Thread ydjango
Thank you Paul. I will use those tools.

I also plan to replace to some ORM queries by raw sql to avoid performance 
impact of cloning and multi db enhancements. 


On Tuesday, August 21, 2012 7:42:26 AM UTC-7, Paul Backhouse wrote:
>
> On Tue, 2012-08-21 at 07:30 -0700, ydjango wrote: 
> > 
> >  I have typical LAMP stack application. I use ORM very heavily. I 
> > recently migrated from django 1.1 to django 1.3.1. 
> > Application has become very slow even though I have doubled the 
> > hardware. 
> > 
> > Two major changes have been: 
> > 1) I have moved database (mysql) to different server 
> > 2) I have migrated django from 1.1 to 1.3.1 
> > 
> > Any clues on what I should look at? 
> > Any Django 1.3.1 specific settings I should look at? 
>
> I think there are some browser tools that you could look at installing. 
> Firebug will tell you details about time to fetch files. I think there's 
> yslow too. Django debug toolbar will also tell you what queries are 
> being made and how long they take. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oZgj3XXlBMwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: new to django

2012-08-21 Thread maha
.don know what to do after that..

>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/m5g03N065jAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



CACHE_MIDDLEWARE_ANONYMOUS_ONLY does not work if user is not printed by view or template

2012-08-21 Thread Alexis Bellido
Hello,

I am working on a Django 1.4 project and writing one simple application 
using per-site cache as described here:

https://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache

I have correctly setup a local Memcached server and confirmed the pages are 
being cached.

Then I set CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True because I don't want to 
cache pages for authenticated users.

I'm testing with a simple view that returns a template with 
render_to_response and RequestContext to be able to access user information 
from the template and the caching works well so far, meaning it caches 
pages just for anonymous users.

And here's my problem. I created another view using a different template 
that doesn't access user information and noticed that the page was being 
cached even if the user was authenticated. After testing many things I 
found that authenticated users were getting a cached page if the template 
didn't print something from the user context variable. It's very simple to 
test: print the user on the template and the page won't be cached for an 
authenticated user, remove the user on the template, refresh the page while 
authenticated and check the HTTP headers and you will notice you're getting 
a cached page. You should clear the cache between changes to see the 
problem more clearly.

I tested a little more and found that I could get rid of the user in the 
template and print request.user right on the view (which prints to the 
development server console) and that also fixed the problem of showing a 
cached page to an authenticated user but that's an ugly hack.

A similar problem was reported here but never got an answer:

https://groups.google.com/d/topic/django-users/FyWmz9csy5g/discussion

I can probably write a conditional decorator to check if 
user.is_authenticated() and based on that use @never_cache on my view but 
it seems like that defeats the purpose of using per-site cache, doesn't it?

Any suggestions will be appreciated.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/dZx3IJsXp9EJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: issues with file upload

2012-08-21 Thread 软刀
finished
sorry, I clone the new source( for review) but use an old source on python 
environment



在 2012年8月21日星期二UTC+8下午6时36分46秒,软刀写道:
>
>
> I now  work with mongoengine, mongoForm
> and set this in setting.py
> DEFAULT_FILE_STORAGE = 'mongoengine.django.storage.GridFSStorage'
>
> I need to upload a picture, and I wrote a form like this:
>
> from django.forms import ImageField
>
>   from mongoforms import MongoForm
>   from documents import UserProfile
>   
>   class ProfileForm(MongoForm):
>   photo = ImageField()
>   class Meta:
>   document = UserProfile
>   exclude = ('user', 'photo')
>
> but I get a Invalid Image Error when I submit a picture( how ever, it's ok 
> when I use PIL.Image.open(photo).verify() )
> I review the code, and found the exception was raise on 
> django.forms.fields.ImageField.to_python method
> code snippet for to_python method:
>   def to_python(self, data):
>
>if hasattr(data, 'temporary_file_path'):
>   file = data.temporary_file_path()
>
>try:
> Image.open(file).verify()
> except ImportError:
> raise
> except Exception: # Python Imaging Library doesn't recognize it as 
> an image
> raise ValidationError(self.error_messages['invalid_image'])
> ...
>
>well, I don't know well to set temporary_file_path and how to 
> storage it with mongoengine.django.storage.GridFSStorage
>
>
> # this was snippet for class ImageField
> def to_python(self, data):
> """
> Checks that the file-upload field data contains a valid image 
> (GIF, JPG,
> PNG, possibly others -- whatever the Python Imaging Library 
> supports).
> """
> f = super(ImageField, self).to_python(data)
> if f is None:
> return None
>
> # Try to import PIL in either of the two ways it can end up 
> installed.
> try:
> from PIL import Image
> except ImportError:
> import Image
>
> # We need to get a file object for PIL. We might have a path or we 
> might
> # have to read the data into memory.
> if hasattr(data, 'temporary_file_path'):
> file = data.temporary_file_path()
> else:
> if hasattr(data, 'read'):
> file = StringIO(data.read())
> else:
> file = StringIO(data['content'])
>
> try:
> # load() could spot a truncated JPEG, but it loads the entire
> # image in memory, which is a DoS vector. See #3848 and #18520.
> # verify() must be called immediately after the constructor.
> Image.open(file).verify()
> except ImportError:
> # Under PyPy, it is possible to import PIL. However, the 
> underlying
> # _imaging C module isn't available, so an ImportError will be
> # raised. Catch and re-raise.
> raise
> except Exception: # Python Imaging Library doesn't recognize it as 
> an image
> raise ValidationError(self.error_messages['invalid_image'])
> if hasattr(f, 'seek') and callable(f.seek):
> f.seek(0)
> return f
>
>  
>
>  
> this was exception stack
>
> Environment:
>
>
> Request Method: POST
> Request URL: http://localhost:8000/accounts/profile/
>
> Django Version: 1.4
> Python Version: 2.7.3
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.messages',
>  'django.contrib.staticfiles',
>  'registration',
>  'bussiness',
>  'accounts',
>  'debug_toolbar']
> Installed Middleware:
> ['django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.contrib.messages.middleware.MessageMiddleware',
>  'debug_toolbar.middleware.DebugToolbarMiddleware']
>
>
> Traceback:
> File 
> "/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/core/handlers/base.py"
>  
> in get_response
>   111. response = callback(request, 
> *callback_args, **callback_kwargs)
> File 
> "/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py"
>  
> in _wrapped_view
>   20. return view_func(request, *args, **kwargs)
> File "/home/yan/git/haoyoubang/accounts/views.py" in profile
>   31. processFile(request.FILES['photo'])
> File "/home/yan/git/haoyoubang/accounts/views.py" in processFile
>   21. s = f.clean(photo)
> File 
> "/home/yan/env/haoyoubang/local/lib/python2.7/site-packages/django/forms/fields.py"
>  
> in clean
>   535. return super(FileField, self).clean(data)
> File 
> "/home/yan/env/haoyoubang/local/lib/python2.7/sit

Re: new to django

2012-08-21 Thread Kurtis Mullins
python manage.py runserver
Then open your browser and goto http://localhost:8000

On Tue, Aug 21, 2012 at 12:43 PM, maha  wrote:

> .don know what to do after that..
>
>
>>
>>
>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/m5g03N065jAJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: new to django

2012-08-21 Thread Enyert Viñas
u can just do python manage.py runserver. Then django will create a
"server" at localhost:8000 or 127.0.0.1:8000

2012/8/21 Kurtis Mullins 

> python manage.py runserver
> Then open your browser and goto http://localhost:8000
>
>
> On Tue, Aug 21, 2012 at 12:43 PM, maha  wrote:
>
>> .don know what to do after that..
>>
>>
>>>
>>>
>>>
>>>
>>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/m5g03N065jAJ.
>>
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Can somebody help me on how to handle this scenario?

2012-08-21 Thread Nirmal Sharma

--This is the model definition

FEEDBACK_CHOICES = (
(1, 'FOR'),
(-1, 'AGAINST'),
(0, 'NEUTRAL'),
)


class user (models.Model):
user_name  = models.CharField(max_length=150)


class comments (models.Model):
comment  = models.CharField(max_length=1000)   
root_comment =  models.ForeignKey('self', null=True, blank=True, 
related_name="children")
user_id = models.ForeignKey(user)


class comment_feedback (models.Model):
feedback_user_id = models.ForeignKey(user)
comment_id =   models.ForeignKey(comments)
feedback_type_id =  models.CharField(max_length=20, 
choices=FEEDBACK_CHOICES)
class Meta:
unique_together = [("feedback_user_id", "info_id")]



We are trying build a html page that will do the following.
Once a user logs in, he can write a new comment (that would result in an 
insert into comments table)
Alternatively he can do one of the following:
select a comment of some other user and give his feedback (that would 
result in an insert into comment_feedback table)
select a comment and write his own comment with a feedback on the 
original comment (that would result in an insert into comments table with 
root_comment as the original comment and an insert into comment_feedback 
table for the original comment)

We tried doing this inlineformset_factory and nested formsets. However we 
are quite confused on how to proceed with this. Also the comment_feedback 
table has 2 foreign keys.
How do we handle this at the form and template level? 

Regards
~Nirmal

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oVRPCd9uzpgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can somebody help me on how to handle this scenario?

2012-08-21 Thread Kurtis Mullins
I'd offer to help but I think there may be quite a bit more you should
understand about Django, before-hand. Have you gone through the Tutorial,
yet? Also, just as a general style guideline to follow; class names are
typically Pascal Case (http://c2.com/cgi/wiki?PascalCase) and the User
class may be a bad name to use as the system already provides a User class
which would be better extended by user name.

Sorry that my information isn't more helpful, but you're asking for help
with quite a complex (but somewhat obvious) task and I'm not sure how much
of the underlying technology you fully understand at this point. Not trying
to frown down upon you for asking by any means! I just think it might be
more beneficial if you've got a solid understanding of the basics first.

Maybe if there's a very specific question, I'd be more happy to help.

Good luck!

On Tue, Aug 21, 2012 at 4:57 PM, Nirmal Sharma wrote:

>
> --This is the model definition
>
> FEEDBACK_CHOICES = (
> (1, 'FOR'),
> (-1, 'AGAINST'),
> (0, 'NEUTRAL'),
> )
>
>
> class user (models.Model):
> user_name  = models.CharField(max_length=**150)
>
>
> class comments (models.Model):
> comment  = models.CharField(max_length=**1000)
> root_comment =  models.ForeignKey('self', null=True, blank=True,
> related_name="children")
> user_id = models.ForeignKey(user)
>
>
> class comment_feedback (models.Model):
> feedback_user_id = models.ForeignKey(user)
> comment_id =   models.ForeignKey(comments)
> feedback_type_id =  models.CharField(max_length=**20,
> choices=FEEDBACK_CHOICES)
> class Meta:
> unique_together = [("feedback_user_id", "info_id")]
>
>
>
> We are trying build a html page that will do the following.
> Once a user logs in, he can write a new comment (that would result in an
> insert into comments table)
> Alternatively he can do one of the following:
> select a comment of some other user and give his feedback (that would
> result in an insert into comment_feedback table)
> select a comment and write his own comment with a feedback on the
> original comment (that would result in an insert into comments table with
> root_comment as the original comment and an insert into comment_feedback
> table for the original comment)
>
> We tried doing this inlineformset_factory and nested formsets. However we
> are quite confused on how to proceed with this. Also the comment_feedback
> table has 2 foreign keys.
> How do we handle this at the form and template level?
>
> Regards
> ~Nirmal
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/oVRPCd9uzpgJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can somebody help me on how to handle this scenario?

2012-08-21 Thread Kurtis Mullins
Sorry, I meant to say the "User class which would be better extended using
a User Profile". Documentation:
https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

On Tue, Aug 21, 2012 at 5:03 PM, Kurtis Mullins wrote:

> I'd offer to help but I think there may be quite a bit more you should
> understand about Django, before-hand. Have you gone through the Tutorial,
> yet? Also, just as a general style guideline to follow; class names are
> typically Pascal Case (http://c2.com/cgi/wiki?PascalCase) and the User
> class may be a bad name to use as the system already provides a User class
> which would be better extended by user name.
>
> Sorry that my information isn't more helpful, but you're asking for help
> with quite a complex (but somewhat obvious) task and I'm not sure how much
> of the underlying technology you fully understand at this point. Not trying
> to frown down upon you for asking by any means! I just think it might be
> more beneficial if you've got a solid understanding of the basics first.
>
> Maybe if there's a very specific question, I'd be more happy to help.
>
> Good luck!
>
>
> On Tue, Aug 21, 2012 at 4:57 PM, Nirmal Sharma wrote:
>
>>
>> --This is the model definition
>>
>> FEEDBACK_CHOICES = (
>> (1, 'FOR'),
>> (-1, 'AGAINST'),
>> (0, 'NEUTRAL'),
>> )
>>
>>
>> class user (models.Model):
>> user_name  = models.CharField(max_length=**150)
>>
>>
>> class comments (models.Model):
>> comment  = models.CharField(max_length=**1000)
>> root_comment =  models.ForeignKey('self', null=True, blank=True,
>> related_name="children")
>> user_id = models.ForeignKey(user)
>>
>>
>> class comment_feedback (models.Model):
>> feedback_user_id = models.ForeignKey(user)
>> comment_id =   models.ForeignKey(comments)
>> feedback_type_id =  models.CharField(max_length=**20,
>> choices=FEEDBACK_CHOICES)
>> class Meta:
>> unique_together = [("feedback_user_id", "info_id")]
>>
>>
>>
>> We are trying build a html page that will do the following.
>> Once a user logs in, he can write a new comment (that would result in an
>> insert into comments table)
>> Alternatively he can do one of the following:
>> select a comment of some other user and give his feedback (that would
>> result in an insert into comment_feedback table)
>> select a comment and write his own comment with a feedback on the
>> original comment (that would result in an insert into comments table with
>> root_comment as the original comment and an insert into comment_feedback
>> table for the original comment)
>>
>> We tried doing this inlineformset_factory and nested formsets. However we
>> are quite confused on how to proceed with this. Also the comment_feedback
>> table has 2 foreign keys.
>> How do we handle this at the form and template level?
>>
>> Regards
>> ~Nirmal
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/oVRPCd9uzpgJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



I LOVE THIS COMMUNITY!

2012-08-21 Thread Mario Gudelj
I just want to tell you guys that you're awesome! I've never seen a
community which helps noobs so much and with so few dickheads in it. Good
on you!

Mario

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Handling millions of rows + large bulk processing (now 700+ mil rows)

2012-08-21 Thread ApogeeGMail
I would VERY interested..

Thanks

Richard
On Jun 30, 2012, at 11:10 AM, Cal Leeming [Simplicity Media Ltd] wrote:

> Hi all,
> 
> As some of you know, I did a live webcast last year (July 2011) on our LLG 
> project, which explained how we overcome some of the problems associated with 
> large data processing.
> 
> After reviewing the video, I found that the sound quality was very poor, the 
> slides weren't very well structured, and some of the information is now out 
> of date (at the time it was 40mil rows, now we're dealing with 700+mil rows).
> 
> Therefore, I'm considering doing another live webcast (except this time it'll 
> be recorded+posted the next day, the stream will be available in 1080p, it'll 
> be far better structured, and will only last 50 minutes).
> 
> The topics I'd like to cover are:
> 
> * Bulk data processing where bulk_insert() is still not viable (we went from 
> 30 rows/sec to 8000 rows/sec on bulk data processing, whilst still using the 
> ORM - no raw sql here!!)
> * Applying faux child/parent relationship when standard ORM is too expensive 
> (allows for ORM approach without the cost)
> * Applying faux ORM read-only structure to legacy applications (allows ORM 
> usage on schemas that weren't properly designed, and cannot be changed - for 
> example, vendor software with no source code).
> * New Relic is beautiful, but expensive. Hear more about our plans to make an 
> open source version.
> * Appropriate use cases for IAAS vs colo with SSDs.
> * Percona is amazing, some of the tips/tricks we've learned over.
> 
> If you'd like to see this happen, please leave a reply in the thread - if 
> enough people want this, then we'll do public vote for the scheduled date.
> 
> Cheers
> 
> Cal
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

Richard Smith
apogeedevelopm...@gmail.com



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I LOVE THIS COMMUNITY!

2012-08-21 Thread Babatunde Akinyanmi
Amen to that

On 8/21/12, Mario Gudelj  wrote:
> I just want to tell you guys that you're awesome! I've never seen a
> community which helps noobs so much and with so few dickheads in it. Good
> on you!
>
> Mario
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
Sent from my mobile device

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



View loaded twice / Database entry saved twice

2012-08-21 Thread James Verran
Hi there, I'm trying to capture all url path data. (Except admin, and a
couple other paths.)

At the end of my urls.py file, I'm using r'^(.*)$'... On my associated
view, I make a simple entry into a database - ie:
Test(path=capturedpath).save()

The problem: my database entry is saved twice! Or rather, my view is being
loaded twice. I added a global variable to check- if not
globals()['already_saved']: Test(path=capturedpath).save()

If I adjust the path: r'^test/(.*)$'  all works as expected (here my url
would be 'mysite.com/test/url/data/to/capture'.)

I'm using django 1.4. Any help/thoughts/suggestions would be much
appreciated.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I LOVE THIS COMMUNITY!

2012-08-21 Thread Lachlan Musicman
+1

On Wed, Aug 22, 2012 at 10:49 AM, Babatunde Akinyanmi
 wrote:
> Amen to that
>
> On 8/21/12, Mario Gudelj  wrote:
>> I just want to tell you guys that you're awesome! I've never seen a
>> community which helps noobs so much and with so few dickheads in it. Good
>> on you!
>>
>> Mario
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
> Sent from my mobile device
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: skip fixtures loading on 'manage.py test myapp'

2012-08-21 Thread Karen Tracey
On Mon, Aug 20, 2012 at 12:40 PM, Anton Baklanov wrote:

> and, if anyone is interested, here is the answer -
> http://south.readthedocs.org/en/latest/settings.html#south-tests-migrate
>
>
That link doesn't really explain why south would be loading fixtures that
Django itself wouldn't ordinarily load. Unless...do you have migrations
that are loading fixtures?

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How I do to centralize logins OpenID in django?

2012-08-21 Thread Mustapha Aoussar
Dear sirs,
I have split my Django application into two sites with different databases. I 
use OpenID (python_openid 2.2.5) for authetication/registration but users of 
''site A'' are different from ''site B''. 

How can I do to centralize logins between apps running on different databases?

I have seen this article by Joseph Smarr at Plaxo 
(http://www.netvivs.com/openid-recipe/) and this Stackoverflow question 
(http://stackoverflow.com/questions/4395190/how-do-stackexchange-sites-associate-user-accounts-and-openid-logins)
 but i don't know how can I do this with django. 

Can you help me please?
Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oHVzCzIer48J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I LOVE THIS COMMUNITY!

2012-08-21 Thread Peith Vergil
i agree

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Distinct Values in ModelChoiceField

2012-08-21 Thread Sithembewena Lloyd Dube
Hi Melvyn,

I found your response to the OP interesting, yet I cannot quite follow it.
Even if he sets a unique attribute (presumably Boolean/ Checkbox?), he
would still need a mechanism to filter the result set at runtime? Please
expound?

On Mon, Aug 20, 2012 at 11:12 AM, Melvyn Sopacua wrote:

> On 20-8-2012 0:16, Joseph Mutumi wrote:
>
> > That particular field at times appears multiple times in the database.
> How
> > do I make it
> > only have distinct values?
> >
> > This is a snippet, drop down will have repeated values if same color is
> > entered:
> >
> > class FavoriteColor(models.Model):
> > color = models.CharField(max_length=255)
> >
> > def __unicode__(self):
> > return self.color
> You should invest in fixing the flaw in the design. Set the unique
> attribute on the color field after you manually remove all duplicates
> from the database.
>
>
> --
> Melvyn Sopacua
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Distinct Values in ModelChoiceField

2012-08-21 Thread Melvyn Sopacua
On 22-8-2012 3:04, Sithembewena Lloyd Dube wrote:

> I found your response to the OP interesting, yet I cannot quite follow it.
> Even if he sets a unique attribute (presumably Boolean/ Checkbox?)

Nope, this unique attribute:


By design, the foreign key will now not contain duplicates so distinct
is no longer necessary.
-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django.db.utils.DatabaseError when resyncing django app models

2012-08-21 Thread Mhlanga Bothin
Hi,

I am very new to Django, I have created multiple models in my app. I am using 
postgresql_psycopg2  as my data base. When I run ./manage validate it returns 
without errors, sqlall works fine and when I syncdb it works as expected, the 
issue occurs when I run syncdb a second time I get the following errors:

$ ./manage.py syncdb
 
Creating tables ...
Traceback (most recent call last):
  File "./manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File 
"/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
line 443, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", 
line 196, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", 
line 232, in execute
output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", 
line 371, in handle
return self.handle_noargs(**options)
  File 
"/usr/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py",
 line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/sql.py", 
line 189, in emit_post_sync_signal
interactive=interactive, db=db)
  File "/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", 
line 172, in send
response = receiver(signal=self, sender=sender, **named)
  File 
"/usr/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
 line 54, in create_permissions
auth_app.Permission.objects.bulk_create(objs)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", 
line 140, in bulk_create
return self.get_query_set().bulk_create(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 
416, in bulk_create
self.model._base_manager._insert(objs_without_pk, fields=[f for f in fields 
if not isinstance(f, AutoField)], using=self.db)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", 
line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 
1576, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 
910, in execute_sql
cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py", 
line 40, in execute
return self.cursor.execute(sql, params)
  File 
"/usr/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py",
 line 52, in execute
return self.cursor.execute(query, args)
django.db.utils.DatabaseError: value too long for type character varying(50)

I have searched google and this list and have not been able to find any help. 
Is there a limit on the amount of classes I cam specify in the models.py file? 
Please let me know if you need any more information. 


Thanks a lot

Cheers

John

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django.db.utils.DatabaseError when resyncing django app models

2012-08-21 Thread Kurtis Mullins
It looks to me like you might have a CharField with a max_length that is
greater than what your Database supports. That's my guess anyways :)

On Tue, Aug 21, 2012 at 9:21 PM, Mhlanga Bothin
wrote:

> Hi,
>
> I am very new to Django, I have created multiple models in my app. I am
> using postgresql_psycopg2  as my data base. When I run ./manage validate it
> returns without errors, sqlall works fine and when I syncdb it works as
> expected, the issue occurs when I run syncdb a second time I get the
> following errors:
>
> $ ./manage.py syncdb
> Creating tables ...
> Traceback (most recent call last):
>   File "./manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 443, in execute_from_command_line
> utility.execute()
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 382, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 196, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 232, in execute
> output = self.handle(*args, **options)
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 371, in handle
> return self.handle_noargs(**options)
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py",
> line 110, in handle_noargs
> emit_post_sync_signal(created_models, verbosity, interactive, db)
>   File
> "/usr/local/lib/python2.7/site-packages/django/core/management/sql.py",
> line 189, in emit_post_sync_signal
> interactive=interactive, db=db)
>   File
> "/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
> line 172, in send
> response = receiver(signal=self, sender=sender, **named)
>   File
> "/usr/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
> line 54, in create_permissions
> auth_app.Permission.objects.bulk_create(objs)
>   File
> "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", line
> 140, in bulk_create
> return self.get_query_set().bulk_create(*args, **kwargs)
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py",
> line 416, in bulk_create
> self.model._base_manager._insert(objs_without_pk, fields=[f for f in
> fields if not isinstance(f, AutoField)], using=self.db)
>   File
> "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", line
> 203, in _insert
> return insert_query(self.model, objs, fields, **kwargs)
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py",
> line 1576, in insert_query
> return query.get_compiler(using=using).execute_sql(return_id)
>   File
> "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
> line 910, in execute_sql
> cursor.execute(sql, params)
>   File
> "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py", line
> 40, in execute
> return self.cursor.execute(sql, params)
>   File
> "/usr/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py",
> line 52, in execute
> return self.cursor.execute(query, args)
> django.db.utils.DatabaseError: value too long for type character
> varying(50)
>
> I have searched google and this list and have not been able to find any
> help. Is there a limit on the amount of classes I cam specify in the
> models.py file? Please let me know if you need any more information.
>
>
> Thanks a lot
>
> Cheers
>
> John
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django.db.utils.DatabaseError when resyncing django app models

2012-08-21 Thread Mhlanga Bothin
Great Thanks I will hunt around for it :)

On 22/08/2012, at 11:56 AM, Kurtis Mullins wrote:

> It looks to me like you might have a CharField with a max_length that is 
> greater than what your Database supports. That's my guess anyways :)
> 
> On Tue, Aug 21, 2012 at 9:21 PM, Mhlanga Bothin  
> wrote:
> Hi,
> 
> I am very new to Django, I have created multiple models in my app. I am using 
> postgresql_psycopg2  as my data base. When I run ./manage validate it returns 
> without errors, sqlall works fine and when I syncdb it works as expected, the 
> issue occurs when I run syncdb a second time I get the following errors:
> 
> $ ./manage.py syncdb
> Creating tables ...
> Traceback (most recent call last):
>   File "./manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
> line 443, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
> line 382, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 
> 196, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 
> 232, in execute
> output = self.handle(*args, **options)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 
> 371, in handle
> return self.handle_noargs(**options)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py",
>  line 110, in handle_noargs
> emit_post_sync_signal(created_models, verbosity, interactive, db)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/sql.py", line 
> 189, in emit_post_sync_signal
> interactive=interactive, db=db)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 
> 172, in send
> response = receiver(signal=self, sender=sender, **named)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
>  line 54, in create_permissions
> auth_app.Permission.objects.bulk_create(objs)
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", 
> line 140, in bulk_create
> return self.get_query_set().bulk_create(*args, **kwargs)
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", 
> line 416, in bulk_create
> self.model._base_manager._insert(objs_without_pk, fields=[f for f in 
> fields if not isinstance(f, AutoField)], using=self.db)
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", 
> line 203, in _insert
> return insert_query(self.model, objs, fields, **kwargs)
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", 
> line 1576, in insert_query
> return query.get_compiler(using=using).execute_sql(return_id)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", 
> line 910, in execute_sql
> cursor.execute(sql, params)
>   File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py", 
> line 40, in execute
> return self.cursor.execute(sql, params)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py",
>  line 52, in execute
> return self.cursor.execute(query, args)
> django.db.utils.DatabaseError: value too long for type character varying(50)
> 
> I have searched google and this list and have not been able to find any help. 
> Is there a limit on the amount of classes I cam specify in the models.py 
> file? Please let me know if you need any more information.
> 
> 
> Thanks a lot
> 
> Cheers
> 
> John
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How I do to centralize logins OpenID in django?

2012-08-21 Thread Kurtis Mullins
I've never tried this approach; but maybe you could use the multi-database
feature of Django to share a database for the Authentication/Sessions
components? (https://docs.djangoproject.com/en/dev/topics/db/multi-db/)

On Tue, Aug 21, 2012 at 7:39 PM, Mustapha Aoussar <
mustapha.aous...@gmail.com> wrote:

> Dear sirs,
> I have split my Django application into two sites with different
> databases. I use OpenID (python_openid 2.2.5) for
> authetication/registration but users of ''site A'' are different from
> ''site B''.
>
> How can I do to centralize logins between apps running on different
> databases?
>
> I have seen this article by Joseph Smarr at Plaxo (
> http://www.netvivs.com/openid-recipe/) and this Stackoverflow question (
> http://stackoverflow.com/questions/4395190/how-do-stackexchange-sites-associate-user-accounts-and-openid-logins)
> but i don't know how can I do this with django.
>
> Can you help me please?
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/oHVzCzIer48J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I LOVE THIS COMMUNITY!

2012-08-21 Thread JJ Zolper
I agree too!

On Tuesday, August 21, 2012 7:38:45 PM UTC-4, Peith wrote:
>
> i agree 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/eqKeF9UQshwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django.db.utils.DatabaseError when resyncing django app models

2012-08-21 Thread Karen Tracey
The key part of the traceback is this:

  File
"/usr/local/lib/python2.7/site-packages/django/core/management/sql.py",
line 189, in emit_post_sync_signal
interactive=interactive, db=db)
  File
"/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py",
line 172, in send
response = receiver(signal=self, sender=sender, **named)
  File
"/usr/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py",
line 54, in create_permissions
auth_app.Permission.objects.bulk_create(objs)

which indicates the problem is related to the creation of permissions for
your models (I can't explain why you are seeing this on a 2nd syncdb unless
you are actually adding models, though I don't see any tables created in
your output so that is a bit confusing). You are hitting this ticket:

https://code.djangoproject.com/ticket/17763

Solution at this point in time is either to shorten names in your models or
manually increase the length of the too-small field(s) in the
auth_permission table.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Question about RSS Feeds and a Weblog

2012-08-21 Thread JJ Zolper
Hello,

I'm considering the act of starting a weblog like the Django one here:

https://www.djangoproject.com/weblog/

on my personal website. This might be a super noob question but does anyone 
know what that runs on? Is it indeed a "blog" underneath the hood? I've 
seen that Django has RSS feeds and that sounds cool too so I wasn't sure if 
that's what the above link runs on?

Any input on going about a sort of "timeline" esque page with entries 
similar to the one of above would be great!

JJ

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_jCkJmiLFtEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Question about RSS Feeds and a Weblog

2012-08-21 Thread Russell Keith-Magee
Django's own site is entirely custom code; you can view the code on Github

http://github.com/django/djangoproject.com

However, you don't need to go the custom route; there are plenty of
blog apps ready to be plugged into your own project, depending on your
exact needs:

http://www.djangopackages.com/grids/g/blogs/

Yours,
Russ Magee %-)

On Wed, Aug 22, 2012 at 11:52 AM, JJ Zolper  wrote:
> Hello,
>
> I'm considering the act of starting a weblog like the Django one here:
>
> https://www.djangoproject.com/weblog/
>
> on my personal website. This might be a super noob question but does anyone
> know what that runs on? Is it indeed a "blog" underneath the hood? I've seen
> that Django has RSS feeds and that sounds cool too so I wasn't sure if
> that's what the above link runs on?
>
> Any input on going about a sort of "timeline" esque page with entries
> similar to the one of above would be great!
>
> JJ
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/_jCkJmiLFtEJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I LOVE THIS COMMUNITY!

2012-08-21 Thread Pervez Mulla
Yup.:) Really its very awesome community :)
On Wed, Aug 22, 2012 at 9:19 AM, JJ Zolper  wrote:

> I agree too!
>
>
> On Tuesday, August 21, 2012 7:38:45 PM UTC-4, Peith wrote:
>>
>> i agree
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/eqKeF9UQshwJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can somebody help me on how to handle this scenario?

2012-08-21 Thread Nirmal Sharma
Hi,

I read all the tutorials and i know the Django basics as well.
I think you misunderstood what i asked.

Dont get confused with the 'user' class i mentioned below with   "User 
class which would be better extended using a User Profile" .
Just to give an example i used the name 'user'.
Let me rephrase the question.

class People (models.Model):
person_name  = models.CharField(max_length=150)


class comments (models.Model):
comment  = models.CharField(max_length=1000)   
root_comment =  models.ForeignKey('self', null=True, blank=True, 
related_name="children")
People_id = models.ForeignKey(People)


class comment_feedback (models.Model):
feedback_People_id = models.ForeignKey(People)
comment_id =   models.ForeignKey(comments)
feedback_type_id =  models.CharField(max_length=20, 
choices=FEEDBACK_CHOICES)
class Meta:
unique_together = [("feedback_People_id", "info_id")]
   
We are trying build a html page that will do the following.
Once a user logs in, he can write a new comment (that would result in an 
insert into comments table)
Alternatively he can do one of the following:
select a comment of some other peoples and give his feedback (that 
would result in an insert into comment_feedback table)
select a comment and write his own comment with a feedback on the 
original comment (that would result in an insert into comments table with 
root_comment as the original comment and an insert into comment_feedback 
table for the original comment)

We tried doing this inlineformset_factory and nested formsets. However we 
are quite confused on how to proceed with this. Also the comment_feedback 
table has 2 foreign keys.
How do we handle this at the form and template level? 

Regards
~Nirmal


On Tuesday, August 21, 2012 1:57:05 PM UTC-7, Nirmal Sharma wrote:
>
>
> --This is the model definition
>
> FEEDBACK_CHOICES = (
> (1, 'FOR'),
> (-1, 'AGAINST'),
> (0, 'NEUTRAL'),
> )
>
>
> class user (models.Model):
> user_name  = models.CharField(max_length=150)
> 
>
> class comments (models.Model):
> comment  = models.CharField(max_length=1000)   
> root_comment =  models.ForeignKey('self', null=True, blank=True, 
> related_name="children")
> user_id = models.ForeignKey(user)
>
>
> class comment_feedback (models.Model):
> feedback_user_id = models.ForeignKey(user)
> comment_id =   models.ForeignKey(comments)
> feedback_type_id =  models.CharField(max_length=20, 
> choices=FEEDBACK_CHOICES)
> class Meta:
> unique_together = [("feedback_user_id", "info_id")]
>
>
>
> We are trying build a html page that will do the following.
> Once a user logs in, he can write a new comment (that would result in an 
> insert into comments table)
> Alternatively he can do one of the following:
> select a comment of some other user and give his feedback (that would 
> result in an insert into comment_feedback table)
> select a comment and write his own comment with a feedback on the 
> original comment (that would result in an insert into comments table with 
> root_comment as the original comment and an insert into comment_feedback 
> table for the original comment)
> 
> We tried doing this inlineformset_factory and nested formsets. However we 
> are quite confused on how to proceed with this. Also the comment_feedback 
> table has 2 foreign keys.
> How do we handle this at the form and template level? 
>
> Regards
> ~Nirmal
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/DMy4tCQfv7cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.