Re: using Django on an existing mysql schema

2015-01-30 Thread Russell Keith-Magee
On Fri, Jan 30, 2015 at 10:47 PM, William Muriithi <
william.murii...@gmail.com> wrote:

> ‎Hello,
>
> I am new to Django and planning to use it for a project I have in mind. I
> am strong in mysql, but not too good in developing. In fact, the secondary
> purpose of this project is to improve my python development skills.
>
> With such a background, I went about doing my data modeling and then set
> up views on top to de normalize the underlying schema and pushing most of
> the business logic in mysql. I want to use Django mainly to insert and
> display, which increases the chance of success with few bugs.
>
> Problem is, with Django, it seems things are done the other way around.
> After playing with it, I noticed it changes the keys from unsigned to
> signed, something I feal is bad from database point of view. It converted
> enum to char, which to me is less appealing. In short, I don't like the
> change its introducing. ‎
>
> My question is, can one use Django with an existing database without
> getting in trouble with the framework? I believe this has to be possible
> somehow as most companies work from data backwards. Would appreciate a good
> advice on how you guys and girls went‎ about using Django from existing
> schema. Or a Django book that take that perspective. The once I have read
> advice me to leave database work to orm.
>

Yes, you can. Django's ORM is there to make your life easier, but there's
no requirement that you use it to create your tables, or even to execute
queries. There's an inspectdb management command to help build wrapper
models for your database; but if you want, you can avoid the ORM entirely,
and use raw database cursors to talk directly to the database.

Of course, if you do this, you're going to miss out on at least some of the
power of Django.

For example, Django has a forms library, which is quite powerful. You can
use it without using Django's ORM. However, if you *are* using Django's
ORM, you can use ModelForms, which is a way to automatically generate a
form for a model.

You're also going to miss out on the community of apps that are out there
to help you get functionality running easily. For example, if you don't
have Django ORM models, then Django's admin interface wont work. A lot of
the power of Django is that it has a good "meta" understanding of the data
in the database; if you take that away, then the functionality that relies
on it obviously wont work.

There's nothing inherently wrong with this - you can code everything
yourself if you want and treat Django as little more than a request routing
library. The only problems you're going to experience are related to the
fact that documentation out there will generally assume that you're using
Django models, not rolling your own. My only concern is that this might
leave you with an odd perception of the capabilities of Django.

Yours,
Russ Magee %-)

-- 
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/CAJxq84-Vf5iTNxH-B2FGnS1sTxT-UA0V%3D4o5axLw_K%2BGpEf%3Dtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: using Django on an existing mysql schema

2015-01-30 Thread Russell Keith-Magee
On Sat, Jan 31, 2015 at 3:14 AM, Tobias Dacoir  wrote:

> I'm certainly no Django expert, but I'm not sure if you can use the orm
> and an already existing database.
>

Yes, you absolutely can. There's even a management command (inspectdb) to
help write the wrapper models, and a Meta flag (managed=False) to make sure
the migration tools won't touch those models.


> However the documentation states that you can write all queries yourself,
> essentially not using the orm. However if you do that, I'm wondering why
> you want to use Django at all?
>

Because Django has a lot more than just an ORM. There's a forms layer,
authentication tools, and lots more.


> And pushing business logic into the database sounds like bad design to me
> (model and controller should be decoupled in MVC like patterns).
>

It depends what logic you're talking about, and what other tools will be
using the same database. "MVC" separation like you are describing assumes
that the Controller is shared; if you have to re-implement the controller
in two languages, then there's a very strong argument to push some of the
controller's functionality into the database.

Yours,
Russ Magee %-)

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


Re: using Django on an existing mysql schema

2015-01-30 Thread Tobias Dacoir
I'm certainly no Django expert, but I'm not sure if you can use the orm and 
an already existing database. However the documentation states that you can 
write all queries yourself, essentially not using the orm. However if you 
do that, I'm wondering why you want to use Django at all?
And pushing business logic into the database sounds like bad design to me 
(model and controller should be decoupled in MVC like patterns).

About the signed and unsigned changes - did you check the documentation: 
https://docs.djangoproject.com/en/1.7/ref/models/fields/
And enum is (afaik) not available in Python, maybe that's why it changed it 
to char.

-- 
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/b7bd5fcc-4093-401e-84fc-8c3175d9ee68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


using Django on an existing mysql schema

2015-01-30 Thread William Muriithi
‎Hello,

I am new to Django and planning to use it for a project I have in mind. I am 
strong in mysql, but not too good in developing. In fact, the secondary purpose 
of this project is to improve my python development skills.

With such a background, I went about doing my data modeling and then set up 
views on top to de normalize the underlying schema and pushing most of the 
business logic in mysql. I want to use Django mainly to insert and display, 
which increases the chance of success with few bugs.

Problem is, with Django, it seems things are done the other way around. After 
playing with it, I noticed it changes the keys from unsigned to signed, 
something I feal is bad from database point of view. It converted enum to char, 
which to me is less appealing. In short, I don't like the change its 
introducing. ‎

My question is, can one use Django with an existing database without getting in 
trouble with the framework? I believe this has to be possible somehow as most 
companies work from data backwards. Would appreciate a good advice on how you 
guys and girls went‎ about using Django from existing schema. Or a Django book 
that take that perspective. The once I have read advice me to leave database 
work to orm.

Regards,

William
‎

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