Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Django': 0.03; 'argument': 0.05; 'subject:Python': 0.06; '(so': 0.07; 'modify': 0.07; 'postgresql': 0.07; 'cursor': 0.09; 'feature.': 0.09; 'mysql.': 0.09; 'orm': 0.09; 'storage.': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'django': 0.11; '2.7': 0.14; 'clauses.': 0.16; 'equivalents': 0.16; 'field).': 0.16; 'increment': 0.16; 'incremented': 0.16; 'rdbms': 0.16; 'rdbms.': 0.16; 'sqlite': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; 'app': 0.19; 'trying': 0.19; 'things.': 0.19; 'addition,': 0.20; 'import': 0.22; 'cc:addr:python.org': 0.22; 'install': 0.23; 'instance,': 0.24; 'text,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'options': 0.25; '>': 0.26; 'first,': 0.26; 'query': 0.26; 'least': 0.26; 'subject:/': 0.26; 'primary': 0.26; 'header:In-Reply-To:1': 0.27; 'appreciated.': 0.29; '(like': 0.30; 'database,': 0.30; 'matching': 0.30; 'start,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'code': 0.31; 'too.': 0.31; 'disabled': 0.31; 'enabled': 0.31; 'gary': 0.31; 'gis': 0.31; 'index,': 0.31; 'searches': 0.31; 'sep': 0.31; 'types.': 0.31; 'file': 0.32; 'this.': 0.32; 'compatible': 0.32; 'figure': 0.32; 'selection': 0.32; 'skip:m 30': 0.32; 'option': 0.32; 'text': 0.33; 'linux': 0.33; 'raw': 0.33; 'trouble': 0.34; 'core': 0.34; 'basic': 0.35; "can't": 0.35; 'common': 0.35; 'created': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'belong': 0.36; 'keyword': 0.36; 'machine.': 0.36; 'right?': 0.36; 'subject:data': 0.36; 'done': 0.36; 'possible': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'being': 0.38; 'implement': 0.38; 'server': 0.38; 'skip:& 10': 0.38; 'auto': 0.38; 'ends': 0.38; 'rich': 0.38; 'anything': 0.39; 'bad': 0.39; 'sure': 0.39; 'major': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'simple,': 0.60; 'most': 0.60; 'helps': 0.61; 'lost': 0.61; 'new': 0.61; 'kind': 0.63; 'field': 0.63; 'sincerely': 0.63; 'provide': 0.64; 'different': 0.65; 'production': 0.68; 'judge': 0.68; 'wish': 0.70; 'quality': 0.72; '"where"': 0.84; '(is': 0.84; 'complexity': 0.84; 'fields,': 0.84; 'fill,': 0.84; 'system:': 0.91; 'these.': 0.91; 'choice.': 0.93; 'inc,': 0.93; 'to:addr:verizon.net': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=58+IRFAx0CcK1cmWF+7enNFLnN39a4JCVioXUtIs1Zc=; b=C+KvL470SZcypsFcX8KbALuM0d1uNUo5yynmaitROqctL3RMu8B5Ak4x8LHdnHSQ3L 7g1iwTwdtHhT/fGzoWdSoquoYkQdfXihAWaiSsCHQ/iBo1HNz36TsF5XVa2ACEJiwe0x 5q+Tj7cy2tGMpXufAJfQC8dCQga+Oob9oAQ6vxnZ7x2A1rT4qiM9iTv3+vvi15IGbQ7a G2gzKgQfmIsXzYrmPQFIXqVCSGnJVSy7J0oXGFh1Xq672kRG70zOlkzkFmIDBlCRL46S IE5RqjkAvnGY7siQLq43Kj0IBprE+Au98LX8iqw9ksgqiM0U/4TVIJ93vRgiiBSnncW4 DuUA== MIME-Version: 1.0 X-Received: by 10.49.24.178 with SMTP id v18mr2209096qef.12.1378286924896; Wed, 04 Sep 2013 02:28:44 -0700 (PDT) In-Reply-To: <5223A8F1.9080905@verizon.net> References: <5223A8F1.9080905@verizon.net> Date: Wed, 4 Sep 2013 10:28:44 +0100 Subject: Re: MySQL data types vs Django/Python data types From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Gary Roach Content-Type: multipart/alternative; boundary=047d7b5d4e5c8ea3ab04e58b6eb6 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 157 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378286933 news.xs4all.nl 16001 [2001:888:2000:d::a6]:34906 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53611 --047d7b5d4e5c8ea3ab04e58b6eb6 Content-Type: text/plain; charset=ISO-8859-1 On 1 Sep 2013 21:54, "Gary Roach" wrote: > > Hi all, > > System: > Debian Wheezy Linux > Python 2.7 > Django 1.5 > MySql 5.5 > > I am new to Python and Django and am having trouble matching Python data types with those of MySQL. MySQL has about 7 basic data types including Blobs, Binaries, etc. It also has a rich selection of geometry types. In addition, types like INT have 7 or 8 different options like Primary Key, zero fill, auto inc, etc. I can't seem to find anything in python to match these. I am trying to build a model.py for an existing database that was created with MySQL Workbench. First, I want to state that you need to understand that Django was designed to help build simple, common use case web apps. Database skins, as someone put it. The ORM is very easy to use, although it is not well prepared for some things. It also has a very nice advantage, which is being compatible with many RDBMS so you can have postgresql on the production server and sqlite on your development machine. This ends up being bad too. For instance, if it is not possible to do something in a specific rdbms, for instance, let's say blobs, Django will not be able to implement it because it has to support those several rdbms. There are many hacks ( http://djangosnippets.org/snippets/1597/ ) but hacks will be hacks and you want your app to be reliable and not compromise your code quality right from the start, right? Many field options have equivalents in Django (primary key, auto increment). You just have to find them. For auto increment there is AutoField. Primary key is an option of the base Field (so you can provide it as a keyword argument to any field). Also if you want gis geometry data types (is that what you meant?) you can install and use geodjango. > I do not wish to use anything other than MySQL because of the complexity of my storage needs (searchable text, PDF, Audio, Video and Photos). The text searches will often be word phrase searches through thousands of documents. I need the speed and the data type flexibility. Are you sure mysql is up to it? For searchable text you will want to have an index, and while mysql's FULLTEXT kind of works, it is clearly not a core feature. Some options for it are enabled or disabled in compile time. Also, I won't judge but it's often wrong to use a rdbms to store PDF/audio/video. Those belong in the file system or nosql storage. > How do I build or modify a model.py to do this. I really don't want to write a model.py manually. That would really be a major pain. Workbench to the database an import to Django and edit is my choice. Unfortunately, the model.py produced has lost most of the functionality of the original database and I can't seem to figure out how to fix it. > > Any help will be sincerely appreciated. > > Gary R. A lot can be done by using the database manually. Django helps you a bit here, for instance it gives you access to the database cursor for raw SQL access to the database, supports custom fields, and every orm query "chain" (like MyModel.objects.all().filter(...)) can be incremented with raw SQL "where" and "select" clauses. But you might not want to be using Django or at least not its ORM. --047d7b5d4e5c8ea3ab04e58b6eb6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 1 Sep 2013 21:54, "Gary Roach" <gary719_list1@verizon.net> wrote:
>
> Hi all,
>
> System:
> =A0 =A0 =A0 =A0 Debian Wheezy Linux
> =A0 =A0 =A0 =A0 Python 2.7
> =A0 =A0 =A0 =A0 Django 1.5
> =A0 =A0 =A0 =A0 MySql 5.5
>
> I am new to Python and Django and am having trouble matching Python da= ta types with those of MySQL. MySQL has about 7 basic data types including = Blobs, Binaries, etc. It also has a rich selection of geometry types. In ad= dition, types like INT have 7 or 8 different options like Primary Key, zero= fill, auto inc, etc. I can't seem to find anything in python to match = these. I am trying to build a model.py for an existing database that was cr= eated with MySQL Workbench.

First, I want to state that you need to understand that Djan= go was designed to help build simple, common use case web apps. Database sk= ins, as someone put it. The ORM is very easy to use, although it is not wel= l prepared for some things.

It also has a very nice advantage, which is being compatible= with many RDBMS so you can have postgresql on the production server and sq= lite on your development machine. This ends up being bad too. For instance,= if it is not possible to do something in a specific rdbms, for instance, l= et's say blobs, Django will not be able to implement it because it has = to support those several rdbms.

There are many hacks ( http://djangosnippets.org/snippets/1597/ ) but hacks wi= ll be hacks and you want your app to be reliable and not compromise your co= de quality right from the start, right?

Many field options have equivalents in Django (primary key, = auto increment). You just have to find them. For auto increment there is Au= toField. Primary key is an option of the base Field (so you can provide it = as a keyword argument to any field).

Also if you want gis geometry data types (is that what you m= eant?) you can install and use geodjango.

> I do not wish to use anything other than MySQL because of the complexi= ty of my storage needs (searchable text, PDF, Audio, Video and Photos). The= text searches will often be word phrase searches through thousands of docu= ments. I need the speed and the data type flexibility.

Are you sure mysql is up to it? For searchable text you will= want to have an index, and while mysql's FULLTEXT kind of works, it is= clearly not a core feature. Some options for it are enabled or disabled in= compile time. Also, I won't judge but it's often wrong to use a rd= bms to store PDF/audio/video. Those belong in the file system or nosql stor= age.

> How do I build or modify a model.py to do this. I reall= y don't want to write a model.py manually. That would really be a major= pain. Workbench to the database an import to Django and edit is my choice.= Unfortunately, the model.py produced has lost most of the functionality of= the original database and I can't seem to figure out how to fix it. >
> Any help will be sincerely appreciated.
>
> Gary R.

A lot can be done by using the database manually. Django hel= ps you a bit here, for instance it gives you access to the database cursor = for raw SQL access to the database, supports custom fields, and every orm q= uery "chain" (like MyModel.objects.all().filter(...)) can be incr= emented with raw SQL "where" and "select" clauses.

But you might not want to be using Django or at least not it= s ORM.

--047d7b5d4e5c8ea3ab04e58b6eb6--