Entity has an event Lifecycle, how does Django do it?

2012-12-19 Thread Glyn Jackson
In other languages and frameworks I have used when you have an entity such 
as user. Each entity has an event lifecycle i.e. post update, pre update, 
post save etc

The following code below is my first save using Django. But its looks very 
messy, it should be than user has a pre create for member and member has a 
pre create for user depending on which way you are coming at it 
In Django is this possible?  


in my views.py


 user = User.objects.create_user(

username=form.cleaned_data.get()['username'],

email=form.cleaned_data['email'], 

password=form.cleaned_data['password']
)
user.save()
member = Member(
user=user,
name=form.cleaned_data['name']
)
member.save()

-- 
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/-/M2vbXJQCJQAJ.
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 community, is it active?

2012-12-19 Thread Glyn Jackson
@Cal Leeming 

some really useful information and very honest. I'm loving using Django!

-- 
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/-/6tebKj_Jg-wJ.
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 community, is it active?

2012-12-19 Thread Glyn Jackson
@Odagi

point well made. thanks for everyone for being so welcoming :0 I spent 
today building my first Django local site, 
ended up with 4 apps. taken me awhile to get my head around things i ended 
up with

registration
  - handles my user signed
security
 - login, logout
web 
 - flat pages etc
- rewards
 - a simple api link to an existing platform in java

given this was my first time really playing with the framework, well it 
conforms to what i'm use to in java and ColdFusion, 
views are almost the same as CF MVC. at some point i will do a write up on 
my blog http://www.glynjackson.org/blog/ (plug, plug) 

so i have some of the basic stuff down with models and views, I'm sure i 
will have lost of stupid questions in the coming months. 

I go to some cons so why not add another one to my list (my wife will kill 
me)!!!


again thanks :)







On Tuesday, December 18, 2012 9:36:42 PM UTC, Glyn Jackson wrote:
>
> I'm hoping this is the right place to ask such questions, please forgive 
> me if not.
>
> I'm making a real time investment in learning another server side 
> language. I have 10 years ColdFusion, 5 years  PHP, JAVA. Having never 
> touched Python let alone the framework Django, for the past 4 weeks I have 
> been testing Django out. Darn, Raspberry Pi started me with my blog (
> http://www.glynjackson.org/blog/) I have to say its nice, however my 
> concerns are now to do with the community and not so much with the 
> framework itself.
>
> No one likes to back a loser and every time I search for Django community 
> I'm faced with a host of negative posts. for example: 
> http://news.ycombinator.com/item?id=2777883  
>
> Unlike other languages I'm active in and still use, I'm also finding it 
> hard to find any user groups locally in the UK (I'm based in Manchester, 
> UK).
>
> So from the community itself how alive is Django? Should I really invest 
> the time to learn? Does it have a real future and please be honest.
>
> other questions
>
> 1) is this worth going? --- http://2013.djangocon.eu
> 2) who are the top blogs people within the Django community who should I 
> be following, blogs feed etc.
>
> Sorry for the stupid questions, but and just want a new skillset that I 
> can use for many years to come. Django is really cool
>
>
>
>
>
>
>
>
>
>

-- 
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/-/IEh4i5vg2qAJ.
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: Entity has an event Lifecycle, how does Django do it?

2012-12-20 Thread Glyn Jackson
@Russel, right, now I know what i'm looking for it makes it easier lol. 
thank you signals is what I needed.

On Wednesday, December 19, 2012 11:29:28 PM UTC, Russell Keith-Magee wrote:
>
> Hi Glyn,
>
> What you're calling "events", Django calls "signals" [1]. In particular, 
> I'm guessing you're looking for the pre_save and post_save signals.
>
> [1] https://docs.djangoproject.com/en/dev/topics/signals/
>
> Yours,
> Russ Magee %-)
>
> On Wed, Dec 19, 2012 at 5:53 PM, Glyn Jackson 
> > wrote:
>
>> In other languages and frameworks I have used when you have an entity 
>> such as user. Each entity has an event lifecycle i.e. post update, pre 
>> update, post save etc
>>
>> The following code below is my first save using Django. But its looks 
>> very messy, it should be than user has a pre create for member and member 
>> has a pre create for user depending on which way you are coming at it 
>> In Django is this possible?  
>>
>>
>> in my views.py
>>
>>
>>  user = User.objects.create_user(
>> 
>> username=form.cleaned_data.get()['username'],
>> 
>> email=form.cleaned_data['email'], 
>> 
>> password=form.cleaned_data['password']
>> )
>> user.save()
>> member = Member(
>> user=user,
>> name=form.cleaned_data['name']
>> )
>> member.save()
>>
>> -- 
>> 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/-/M2vbXJQCJQAJ.
>> 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/-/Qzjj1aDVJRMJ.
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.



Code guidance please review.

2012-12-25 Thread Glyn Jackson
Hi,

I'm new to Django and just need some guidance.

Below is my attempt at creating a simple app that displays all transactions 
and lists the grand total called 'points' for a particular user. Now the 
following works and does just that, however, I'm not 100% if this is the 
'correct' way nor really what a 'manager' is.

Could someone look at the following code and advice?

Many, many thanks O, and Happy Christmas everyone!


models.py

from django.db import models
from django.contrib.auth.models import User




class TransactionManager(models.Manager):

def Transaction_list(self,thisUser):
list = Transaction.objects.filter(user=thisUser)
return list

def points_total(self,thisUser):
return  
Transaction.objects.filter(user=thisUser).aggregate(total_points=models.Sum('points'))



class Transaction (models.Model):

statusOptions = (
(0, 'Pending'),
(1, 'Added'),
(2, 'Deducted'),
(3, 'Processing'),
)

user = models.ForeignKey(User)
points = models.IntegerField(verbose_name=("Points"), default=0)
created = models.DateTimeField(("Created at"), auto_now_add=True)
updated = models.DateTimeField(verbose_name=("Updated at"), 
auto_now=True)
status = models.IntegerField(default=0, choices=statusOptions)

objects = TransactionManager()


views.py

from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from points.models import Transaction

@login_required
def history(request):

thisPoints = Transaction.objects.Transaction_list(request.user)
totalPoints = Transaction.objects.points_total(request.user)
context = {'points':thisPoints,'totalPoints':totalPoints}
return render_to_response('points/history.html', context, 
context_instance=RequestContext(request))


-- 
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/-/rskcynXm0NAJ.
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: Code guidance please review.

2012-12-26 Thread Glyn Jackson
ke1g, thank you for such a well written reply, clearly explained, I learn a 
lot. again thanks.

The only bit I'm struggling to understand is the last part you state

"The use of "thisPoints" in calculating "totalPoints" doesn't change 
"thisPoints".  You can still enumerate it in the template, and get the same 
result."


-- 
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/-/iJtWTRu4Id4J.
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: Code guidance please review.

2012-12-28 Thread Glyn Jackson
thank you again Bill :0 makes perfect sense now.

On Thursday, December 27, 2012 12:35:16 AM UTC, ke1g wrote:
>
>
>
> On Wed, Dec 26, 2012 at 3:50 PM, Glyn Jackson 
> > wrote:
>
>> ke1g, thank you for such a well written reply, clearly explained, I learn 
>> a lot. again thanks.
>>
>> The only bit I'm struggling to understand is the last part you state
>>
>> "The use of "thisPoints" in calculating "totalPoints" doesn't change 
>> "thisPoints".  You can still enumerate it in the template, and get the same 
>> result."
>>
>
> Manager and queryset methods like "filter" return a new queryset, which is 
> a python class instance holding all the things that you have said about 
> your query, but it hasn't touched the database as yet.  When you use 
> something like "filter" on an existing queryset, the original information 
> is still in the original queryset, it has been copied as necessary in the 
> construction of the new queryset.
>
> A queryset is "evaluated" only when you try to use what's in the queryset, 
> such as "list(qs)" or "for r in qs" (including the template language's 
> "for"), or when you print it in the manage.py shell, as examples.  And only 
> when it is evaluated, does it wind up composing SQL, send it to the 
> database, parse the result into model instances (and cacheing these as part 
> of doing requests with large numbers of results in chunks, among other 
> things).  You really get quite a number of splendid optimizations when you 
> use the ORM.
>
> So at the time I showed applying "aggregate" to the "thisPoints" queryset, 
> "thisPoints" hadn't touched the database.  At that time, it is specifically 
> NOT a list of instances.  It is still a queryset class instance.  And the 
> "aggregate" method uses what's in it, but doesn't change it.  Later, in 
> your template, where you presumably apply a "for" template tag to it, is 
> when it uses what it knows to get stuff for you from the database.
>
> Bill
>

-- 
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/-/Eo93nblTwTkJ.
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 admin save error: get_db_prep_value() got an unexpected keyword argument 'connection'

2013-01-03 Thread Glyn Jackson
I really struggling with my understanding of the following issue and how to 
resolve 





When I try and save (using the Django standard admin interface) I get the 
following error... 

TypeError at /admin/web/campaign/dc6eb21f-87fa-462f-88af-416cf6be37f6/
> 
> get_db_prep_value() got an unexpected keyword argument 'connection'
>

Could someone explain this to me, why and maybe a possible solution? I'm 
assuming it is something to do with my custom HibernateBooleanField field. 

Full error and details below. 

**Error**


Environment:
> 
> 
> Request Method: POST
> Request URL: 
> http://127.0.0.1:8000/admin/web/campaign/dc6eb21f-87fa-462f-88af-416cf6be37f6/
> 
> Django Version: 1.4.2
> Python Version: 2.7.2
> Installed Applications:
> ('django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.flatpages',
>  'django.contrib.messages',
>  'django.contrib.staticfiles',
>  'grappelli.dashboard',
>  'grappelli',
>  'django.contrib.admin',
>  'django.contrib.admindocs',
>  'web')
> 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')
> 
> 
> Traceback:
> File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" 
> in get_response
>   111. response = callback(request, 
> *callback_args, **callback_kwargs)
> File 
> "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in 
> wrapper
>   366. return self.admin_site.admin_view(view)(*args, 
> **kwargs)
> File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in 
> _wrapped_view
>   91. response = view_func(request, *args, 
> **kwargs)
> File 
> "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in 
> _wrapped_view_func
>   89. response = view_func(request, *args, **kwargs)
> File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" 
> in inner
>   196. return view(request, *args, **kwargs)
> File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in 
> _wrapper
>   25. return bound_func(*args, **kwargs)
> File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in 
> _wrapped_view
>   91. response = view_func(request, *args, 
> **kwargs)
> File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in 
> bound_func
>   21. return func(self, *args2, **kwargs2)
> File "/Library/Python/2.7/site-packages/django/db/transaction.py" in 
> inner
>   209. return func(*args, **kwargs)
> File 
> "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in 
> change_view
>   1054. self.save_model(request, new_object, form, 
> True)
> File 
> "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in 
> save_model
>   709. obj.save()
> File "/Library/Python/2.7/site-packages/django/db/models/base.py" in 
> save
>   463. self.save_base(using=using, force_insert=force_insert, 
> force_update=force_update)
> File "/Library/Python/2.7/site-packages/django/db/models/base.py" in 
> save_base
>   529. rows = 
> manager.using(using).filter(pk=pk_val)._update(values)
> File "/Library/Python/2.7/site-packages/django/db/models/query.py" in 
> _update
>   560. return query.get_compiler(self.db).execute_sql(None)
> File 
> "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in 
> execute_sql
>   986. cursor = super(SQLUpdateCompiler, 
> self).execute_sql(result_type)
> File 
> "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in 
> execute_sql
>   808. sql, params = self.as_sql()
> File 
> "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in 
> as_sql
>   951. val = field.get_db_prep_save(val, 
> connection=self.connection)
> File 
> "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py" in 
> get_db_prep_save
>   292.   prepared=False)
> 
> Exception Type: TypeError at 
> /admin/web/campaign/dc6eb21f-87fa-462f-88af-416cf6be37f6/
> Exception Value: get_db_prep_value() got an unexpected keyword 
> argument 'connection'
>
>
>
> **model**
>
> class Campaign(models.Model):
> campaignid = models.CharField(max_length=255, primary_key=True, 
> db_column='campaignID')
> na

Django superstars I should be following?

2013-02-05 Thread Glyn Jackson
I'm looking for suggestions on who to follow on twitter. 
Who are the Django superstars, and the opinionated and guy/grils I should 
be following?


:) Thanks in advance.


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




Re: Django superstars I should be following?

2013-02-05 Thread Glyn Jackson
thanks  :) perfect.

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




Re: django tut 01

2014-07-28 Thread Glyn Jackson
You need to be a little more detailed about your error. When you say "Can't 
access database sqlite3" are you referring to permissions? Please post your 
settings. 

In the mean, time check you have the correct read/write permissions on the 
directory.Try "sudo python manage.py syncdb" (notice the word sudo). If 
this works you don't have the correct permission setup.  

On Monday, July 28, 2014 9:48:21 AM UTC+1, atul...@iiitd.ac.in wrote:
>
> Can't access database sqlite3. I am beginner . I cant use the database 
> when i run command " python manage.py syncdb".
> Please help!
> P.s. Can anyone please tell how to use sqlite3 database ( I know nothing 
> about it )
> Thankyou
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/63273411-53e1-4ba1-b90a-9d657464a460%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I'm getting obsessed! Where should I put this code?

2014-02-09 Thread Glyn Jackson
I'm getting obsessed!

I have an API (TatstyPie) which saves a product. Every time this resource 
is saved I assign stock or rise an error if their is no stock.

*get and allocate some stock:*

stock = Stock.objects.filter(availability="Available", 
product=product)[:1].get()


*check we have stock:*

 except Stock.DoesNotExist:
raise CustomBadRequest(
code="stock",
message="No stock left"
)


*if ok, assign stock to product:*

instance.stock = stock
stock.allocate()



So far I have moved this logic around so many times, but where should it 
really be happening in my Django project? Opinions very much welcome. Thanks

1) product  *pre_save* - this works really well but validation looks odd 
here!
2) product  *model save()* - again validation looks odd here!
3) product *model manager *- this seems bad as I'm referencing the stock 
model in product manager.
4) *views* - I end up repeating the save validation and code looks really 
bad, also I have to do it again for API and normal views
5) *tastypie recourse* - just as bad as views I think.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f561aea1-a788-4093-94ea-af5c1a6d0dbb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I'm getting obsessed! Where should I put this code?

2014-02-10 Thread Glyn Jackson
Thank you so much for all your comments, they were very helpful.

After reading '*a lot*' I think I've found some calm.

I decided to move all validation into validation.py. I then used these 
functions in both forms and the models i.e.


mobile = PhoneNumberField(validators=[validate_mobile])


I found that Django however, does not call the clean method by default when 
saving a model.

I got rid of the signal pre_save I read it was a bad idea! I found that the 
save() method is executed at the same time the `pre_save` -signal was.

def save(self, force_insert=False, force_update=False, *args, **kwargs):
"""
Override of save() method which is executed the same
time the ``pre_save``-signal would be
"""
if not (force_insert or force_update):
self.full_clean()

I feel a lot better now :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1f3b54d4-242b-4d20-ad88-bb52b4316d37%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: heroku better for django?

2014-02-11 Thread Glyn Jackson
If you have a small app it's darn easy. I have personal experience with 
Amazon AWS which is by far a better choice. 
I wrote a guide on setup with Django if it helps:
http://glynjackson.org/weblog/entry/django-15-deployement-amazon-ec2-ubuntu.html

At the end of the day Heroku runs on AWS instances, why not cut out the 
middle man. I personally don't like Platform as a Service (PaaS), AWS offer 
Infrastructure as a Service (IaaS). 

Read more: 
http://www.quora.com/Heroku/How-easy-is-it-to-get-off-Heroku-once-you-grow-out-of-it

As you can see not a big fan.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f4db73b-e645-4c01-8a21-e3d89dfe0d71%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django admin broken after putting into production

2014-02-11 Thread Glyn Jackson

>
> Silly question, don't be offended, but have you run 
> collectstaticon
>  your production server?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0d9f10d8-efbf-477f-a3db-9385b6e51298%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Rest Framework create api-root ???

2014-06-20 Thread Glyn Jackson
The documentation explains this very well: 
http://www.django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/22fe0551-9e82-4fe6-9df4-e2ef99936129%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.