Re: Is there a way to create a new database table other than model?

2010-11-23 Thread Li You
>> Because I want to save user's info about each game. And the best way
>> is to save the info by each game.
>>
>
> It sounds like you have some db modelling confusion here.
>
> Are you sure you don't just want a many-to-many between Game and User
> with some data on an explicit through model "UserGameInfo" with some
> per-user per-game data?
>
> http://docs.djangoproject.com/en/1.2/topics/db/models/#extra-fields-on-many-to-many-relationships

ok, this is a way.

Let me describe this problem in more detail:
I have a Game model for each game. This model can be seen as a list of
all games, such as,

class Game(models.Model):
name = models.CharField(max_length = 128, unique = True)
available = models.BooleanField(default = True)
timestamp = models.DateTimeField(auto_now_add=True)

And usually a user just plays with a few of games, but there maybe
hundreds of games.
A user may have different level in different games, so I need to keep
record of the user's level in each game.

At the beginning, I want to create a table for each game. Only users
who play that game get their level logged in the game's table.

By using many-to-many field, I can record the level info of all games
in a single table. But I am a little afraid of the performance...

That is the origin of this question. Thank you all. :)

-- 
Best Regards!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 do i get access to json data?

2010-11-23 Thread Li You
sorry but a mistake.

On Tue, Nov 23, 2010 at 10:01 PM, Li You  wrote:
> Maybe this is what you want:
>
> from json import JSONDecoder
> s = '''{
>    "pk": 1,
>    "model": "store.book",
>    "fields": {
>        "name": "Mostly Harmless",
>        "author": ["Douglas", "Adams"]
>    }
> }
> '''
> d = JSONDecoder().decode(s)
>
> print a['fields']['author']
~~~ should be
print d['fields']['author']
>
> On Tue, Nov 23, 2010 at 9:45 PM, alecx
>  wrote:
>> Hello django users,
>>
>> after several try outs, i am not able to figure out how to access data
>> in a serialized object.
>> E. g. how do I get the name "Douglas", "Adams" in the example:
>> http://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys
>>
>> In javascript i can get e. g. the "name": "Mostly Harmless" with:
>> this.fields.name.
>> But how do i get the "author": ["Douglas", "Adams"]?
>> I tried serveral options, but had no luck.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>>
>
>
>
> --
> Best Regards!
>
> Li You
> University of Science and Technology of China
>



-- 
Best Regards!

Li You
University of Science and Technology of China

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 do i get access to json data?

2010-11-23 Thread Li You
Maybe this is what you want:

from json import JSONDecoder
s = '''{
"pk": 1,
"model": "store.book",
"fields": {
"name": "Mostly Harmless",
"author": ["Douglas", "Adams"]
}
}
'''
d = JSONDecoder().decode(s)

print a['fields']['author']

On Tue, Nov 23, 2010 at 9:45 PM, alecx
 wrote:
> Hello django users,
>
> after several try outs, i am not able to figure out how to access data
> in a serialized object.
> E. g. how do I get the name "Douglas", "Adams" in the example:
> http://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys
>
> In javascript i can get e. g. the "name": "Mostly Harmless" with:
> this.fields.name.
> But how do i get the "author": ["Douglas", "Adams"]?
> I tried serveral options, but had no luck.
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>



-- 
Best Regards!

Li You
University of Science and Technology of China

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Is there a way to create a new database table other than model?

2010-11-23 Thread Li You
Because I want to save user's info about each game. And the best way
is to save the info by each game.

On Tue, Nov 23, 2010 at 9:26 PM, ringemup  wrote:
> Perhaps there's another way to accomplish your goal.  Why do you want
> a table for each game?
>
> On Nov 23, 5:14 am, vbs  wrote:
>> Hi all,
>>
>> This is my situation, I want to make a web based game-hall.
>> I have a model named Game. When I add a new game from the admin panel,
>> a new record will be added to the database table assigned to model
>> Game. This is what django does.
>> And at the same time, I also want a new database table to be created,
>> named as the name of the new game, or with some prefix. It's best to
>> have a model assigned to this table.
>>
>> Is there any way to do this?
>>
>> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>



-- 
Best Regards!

Li You
University of Science and Technology of China

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Is there a way to create a new database table other than model?

2010-11-23 Thread Li You
Is there a prettier way to do it?

Maybe a dynamic model, or nested model, or something like?

On Tue, Nov 23, 2010 at 9:42 PM, S Basl  wrote:
> If you absolutely need to do so, you can execute raw sql queries to do
> whatever you need using Django. The docs are
> here: http://docs.djangoproject.com/en/1.2/topics/db/sql/
> However, it's probably a 'bad' idea to go mucking about with sql if you can
> at all avoid it.
>
> On Tue, Nov 23, 2010 at 8:26 AM, ringemup  wrote:
>>
>> Perhaps there's another way to accomplish your goal.  Why do you want
>> a table for each game?
>>
>> On Nov 23, 5:14 am, vbs  wrote:
>> > Hi all,
>> >
>> > This is my situation, I want to make a web based game-hall.
>> > I have a model named Game. When I add a new game from the admin panel,
>> > a new record will be added to the database table assigned to model
>> > Game. This is what django does.
>> > And at the same time, I also want a new database table to be created,
>> > named as the name of the new game, or with some prefix. It's best to
>> > have a model assigned to this table.
>> >
>> > Is there any way to do this?
>> >
>> > Thank you.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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-us...@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.
>



-- 
Best Regards!

Li You
University of Science and Technology of China

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.