CMS for Online News Paper

2015-10-02 Thread Milind Singh
I am a beginner, and working on my first django based project - a wevsite with 
CMS for Online News Paper.
Dear expert kindly suggest me with:
1. Structure
2. How to use portlets
3. Extending django admin  , etc
 Thanks in advance
-Milind

-- 
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/84049326-a8b0-45be-ab9e-52ae1f028814%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Finding average

2015-10-02 Thread Tim Graham
Please have a look at the aggregation docs and see if you can figure it out:

https://docs.djangoproject.com/en/stable/topics/db/aggregation/

On Friday, October 2, 2015 at 2:46:39 AM UTC-4, Bhanu Kathuria wrote:
>
> I have attached my model files and template files. Please tell how can i 
> find avg of rating for a particular college. In current format it is 
> displaying rating of all colleges correctly.
> Along with this I also want to add avg ratings for college.
> I have used foriegn key in this.
>

-- 
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/61afabd5-b57b-4d9d-9fbd-aa6b2d7f95a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Foreign key in sqlite3

2015-10-02 Thread Ricardo Daniel Quiroga
add foreign key in model, not in database, but it can cause conflicts with
django.
anyway if you even want to do it reviews the documentation SQLite

2015-09-30 13:12 GMT-03:00 Gergely Polonkai :

> Assuming you are using Django and it's ORM, the same way as in any other
> database:
>
> fieldname = models.ForeignKey(AnotherModel)
> On 30 Sep 2015 15:18, "Bhanu Kathuria" <001kathuriabh...@gmail.com> wrote:
>
>> I am using sqlite3 database.
>> How can I add foreign key between two tables.
>>
>> --
>> 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/56c957c9-6b03-4c19-9566-9a63cdbf8319%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/CACczBUKyATKexddYKEMhKyg4SpywuyZ7uMxDK5HMXxadQV7vLg%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Ricardo Daniel Quiroga

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


Method call at end of Django session

2015-10-02 Thread Amarjeet Kapoor
Want to know how and where can I implement a method in Django which is
to called automatically only when a session end ( i.e. when user close
the webapp or browser ). I want to know where that method should be
written, how to call it automatically  after end of session.

I want to use this method to delete some user specific files created
after background processing in my webapp.


-- 
Amarjeet Singh
https://amarjeetkapoor1.wordpress.com
https://github.com/amarjeetkapoor1
https://bitbucket.org/amarjeetkapoor

-- 
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/CABskhPPQV%2BPXe-ObEbb05Bk7KpbLcv1XB__jhx2d-Q54qBzSZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Why should we use Django Rest Framework?

2015-10-02 Thread Robert librado
>From what ive seen when i use it its like django admin but with more 
features.
I also noticed that it has the serializers are those for like using it with 
a machine ot translatign code? 
I also have question on why its needed i understand that the api is for 
client and users to collect data is that the whole point for an api so that 
an end user could embedd info or to tap into ? 

can someone explain to to me why its needed? 

-- 
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/02262f0c-862e-454b-a70b-79fb48670efa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending mail using smtp server

2015-10-02 Thread Robert librado
when ive used this method ive experience errors the port 587 seems to have 
issues. 
could you post some basic code. that would work 
for anybody 
please thanks 
email me back 
djangocharm2...@gmail.com thanks 

On Monday, September 28, 2015 at 5:56:42 PM UTC-5, Rajat Singh wrote:
>
> I want to know the how to send mail using google smtp server in django
>

-- 
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/ea41f86f-c813-4715-afd3-4a88747cd08c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why should we use Django Rest Framework?

2015-10-02 Thread Andreas Kuhne
Hi Robert,

The main reason for using django rest framework is if you need a backend to
communicate with one or more rich frontends. An example could be if you
have a website running django and you want to create a mobile application
for iOS or android. You can then create an API that will communicate with
your django server via the django rest framework.

There is also a vast difference between the django admin site and the
django rest framework. I normally use the Django Admin site to add items to
the database that are needed for my datamodel. For example user groups with
permissions. The django rest framework creates a complete REST API with
json or xml representations of your models. However you can also browse the
API via HTML to check what it looks like and also use that as the
documentation of your API. That can also be switched (I think).

Django Admin cannot be used as a REST API for you models, but you are able
to add / search and delete your data.

Hope that helped a litte!

Regards,

Andréas

2015-10-02 21:43 GMT+02:00 Robert librado :

> From what ive seen when i use it its like django admin but with more
> features.
> I also noticed that it has the serializers are those for like using it
> with a machine ot translatign code?
> I also have question on why its needed i understand that the api is for
> client and users to collect data is that the whole point for an api so that
> an end user could embedd info or to tap into ?
>
> can someone explain to to me why its needed?
>
> --
> 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/02262f0c-862e-454b-a70b-79fb48670efa%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CALXYUbm8M%2Bk_HbQZW2bCiirOurOHJnD%3DwgNssEZSskaWJYsQtA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Method call at end of Django session

2015-10-02 Thread Andreas Kuhne
Hi,

I don't think you can reliably do that. Django never knows when the user
closes his browser window. Because a session is stateless (there is only a
connection to the server when it responds to a request). However you could
do this via a bit of ajax or a pretty unreliable javascript event.

What I would do is to ping the server via javascript once every minute or
so - you then update a timestamp on a session object or the user model or
something like that. Then if the timestamp is older than 5 minutes, you can
safely delete the temporary files.

Another way would be to add an event handler to the onbeforeunload event,
see
http://stackoverflow.com/questions/20853142/trying-to-detect-browser-close-event.
When the event fires, you just fire an ajax call to your server that
deletes the files.

HOWEVER, I know that this doesn't always fire and can be a bit tricky. But
it's worth a shot.

Regards,

Andréas

2015-10-02 18:44 GMT+02:00 Amarjeet Kapoor :

> Want to know how and where can I implement a method in Django which is
> to called automatically only when a session end ( i.e. when user close
> the webapp or browser ). I want to know where that method should be
> written, how to call it automatically  after end of session.
>
> I want to use this method to delete some user specific files created
> after background processing in my webapp.
>
>
> --
> Amarjeet Singh
> https://amarjeetkapoor1.wordpress.com
> https://github.com/amarjeetkapoor1
> https://bitbucket.org/amarjeetkapoor
>
> --
> 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/CABskhPPQV%2BPXe-ObEbb05Bk7KpbLcv1XB__jhx2d-Q54qBzSZQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Converting implicit m2m through table to explicit through model with Django 1.7 migrations

2015-10-02 Thread John Lucas
Thanks for the replies. Carsten - that link is broken for me unfortunately.

Thanks for the thumbs up Simon - appreciate the help. I'll be sure to 
document this once I have a moment. I have one follow up question. Both so 
I can see the proof in the pudding myself and because I'm generally curious 
about how all the magic happens, is there any way to inspect the state of 
the autodetector? By that I mean, I'd like to test that this is 100% 
equivalent to a standard migration solution (i.e. create new field, move 
data to new field, remove old field, create the field again, move the data 
back) by creating both sets of migrations (on separate branches of course) 
and checking the state the autodetector "thinks" it's in at the end of the 
migrations. Is that possible?

On Tuesday, September 29, 2015 at 12:09:25 PM UTC-4, Carsten Fuchs wrote:
>
> Hi John, 
>
> Am 28.09.2015 um 15:54 schrieb John Lucas: 
> > So - is my approach safe? Or will there be complications down the line? 
>
> I've recently had a similar / the same question. See this thread, which 
> also contains 
> the solution that worked very well for me: 
> http://thread.gmane.org/gmane.comp.python.django.user/172038 
>
> Best regards, 
> Carsten 
>

-- 
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/b1e3a540-8fe1-4480-89a8-b7011bf5e277%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why should we use Django Rest Framework?

2015-10-02 Thread James Schneider
>
> From what ive seen when i use it its like django admin but with more
> features.
>

Django Admin is not an API, nor can it be used that way. If you need API
functionality, you would write the interface yourself, or use a package
such as DRF.

DRF and the Django Admin perform the same functionality internally, but
provide two different methods of external interaction. I believe what you
are referring to is the browseable API feature within DRF that may give a
somewhat Django Admin-like feel. (
http://www.django-rest-framework.org/topics/browsable-api/). The browseable
API is designed to guide programmers to the proper use of the API, and not
to be interacted with directly in production.

Django Admin is designed to provide an 'out of the box' user interface that
admins and staff (humans) can use to manage models via a web browser.
Computers, on the other hand, do not use a browser to communicate with
other computers. DRF (and all API's in a broader sense) is designed to
facilitate computer to computer communication (or more succinctly,
application to application).

Here is an example query of a REST API that DRF could potentially be
configured to return in JSON (assuming you had access to all of the
financial data that Yahoo! does):

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json

You can past that in your browser to see what the application would
receive. Obviously this isn't very human-friendly, but to a computer it's
just data and can happily munch away at it.



> I also noticed that it has the serializers are those for like using it
> with a machine ot translatign code?
>

I'm not exactly sure what you mean here, but in DRF, serializers are used
to convert the data values stored in model records to formats used by API
consumers (other applications) such as JSON or XML. The result is generally
something that looks like the data returned from the Yahoo! URL above, or
could be as simple as an HTTP return code of 200 (if no data is returned
from the API call).


> I also have question on why its needed i understand that the api is for
> client and users to collect data is that the whole point for an api so that
> an end user could embedd info or to tap into ?
>

I think I covered this already, but yes, exposing an API provides a way for
other application programmers to integrate data and services that your
application offers into their own applications.


>
> can someone explain to to me why its needed?
>
> I recommend you search around for an explanation of API's in general.

http://money.howstuffworks.com/business-communications/how-to-leverage-an-api-for-conferencing1.htm

-James

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


Re: Method call at end of Django session

2015-10-02 Thread Vijay Khemlani
Also it is most likely inconsistent if the user has the same webpage opened
on two different tabs

On Fri, Oct 2, 2015 at 5:55 PM, Andreas Kuhne 
wrote:

> Hi,
>
> I don't think you can reliably do that. Django never knows when the user
> closes his browser window. Because a session is stateless (there is only a
> connection to the server when it responds to a request). However you could
> do this via a bit of ajax or a pretty unreliable javascript event.
>
> What I would do is to ping the server via javascript once every minute or
> so - you then update a timestamp on a session object or the user model or
> something like that. Then if the timestamp is older than 5 minutes, you can
> safely delete the temporary files.
>
> Another way would be to add an event handler to the onbeforeunload event,
> see
> http://stackoverflow.com/questions/20853142/trying-to-detect-browser-close-event.
> When the event fires, you just fire an ajax call to your server that
> deletes the files.
>
> HOWEVER, I know that this doesn't always fire and can be a bit tricky. But
> it's worth a shot.
>
> Regards,
>
> Andréas
>
> 2015-10-02 18:44 GMT+02:00 Amarjeet Kapoor :
>
>> Want to know how and where can I implement a method in Django which is
>> to called automatically only when a session end ( i.e. when user close
>> the webapp or browser ). I want to know where that method should be
>> written, how to call it automatically  after end of session.
>>
>> I want to use this method to delete some user specific files created
>> after background processing in my webapp.
>>
>>
>> --
>> Amarjeet Singh
>> https://amarjeetkapoor1.wordpress.com
>> https://github.com/amarjeetkapoor1
>> https://bitbucket.org/amarjeetkapoor
>>
>> --
>> 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/CABskhPPQV%2BPXe-ObEbb05Bk7KpbLcv1XB__jhx2d-Q54qBzSZQ%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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/CALXYUbmB-26TtmX6Ughi4mE3SKKVneFLWiJyumP6jGf-byE4pg%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CALn3ei3eNda6GHxWr2%3DCSFs%2Bbf9Rav_nBkJ3tRzbqD5hrn1%2BqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Corrupted Migration?

2015-10-02 Thread Daniel Chen
@Mike: I'm using Python 2.7.10 and Django 1.7. I'm not sure the ticket 
applies, but I appreciate the link!

@James: Sorry, I misspoke! [field] actually corresponds to a old field in 
state X. Before adding the new fields in state Y, the migration is trying 
to remove some old fields in state X but isn't finding them. I think this 
means that I'm unable to re-run that migration since it's looking for state 
X fields to remove, but can't find them (the models is already in state Y). 
My confusion is in the fact that the model state wouldn't roll back to 
state X after the first failed transaction (like the DB did).

This would be analogous to my writing you a check that will bounce. Once 
the check bounces, both your personal wealth and your bank statement should 
be back to what they were originally. But in this particular case, it looks 
like your personal wealth is stuck in a state that assumes the check has 
been cashed and your account has been credited, but your bank account 
disagrees :)

By the way, I talk about model state under the assumption that the Django 
ORM somehow internally keeps track of the models - I'm not sure exactly how 
it does this or if it does this at all.

On Thursday, October 1, 2015 at 1:17:43 AM UTC-7, James Schneider wrote:
>
>
> > I have tried that (by the way, the offending migration didn't show up in 
> the django_migrations table because the migration failed).
> >
> > I think we might be talking past each other. Sorry if I'm being unclear. 
> Here's an example of what's going on:
> > Before migration, my database is at state X, and my migrations files 
> reflect that.
> > I change my model file, updating the state (let's call it state Y). 
> Then, I run make migrations, generating a new migration file that 
> corresponds to state Y.
> > I run the migrate command to get my database to state Y. It fails, so 
> now my database is back at state X. There is nothing in the database to 
> delete (not even from the django_migrations table) because the transaction 
> was rolled back.
> > I delete the migration file that corresponds to state Y. My database is 
> back in state X, and my migration files again reflect that.
> > I run the migrate command again, and it fails (same problem). The error 
> is django.db.models.fields.FieldDoesNotExist: [Model] has no field named 
> [field].
>
> After you delete Y migration, have you searched your migration files to 
> verify that there are no references to that field?
>
> > [field] corresponds to a new field in state Y, not in an existing field 
> in state X. I'm confused - why is it looking for a field that doesn't exist 
> in the pre-migrated state (state X)?
>
> Do you have any RunPython or other custom modifications in your migrations 
> that would cause an object based on your modified model to be created (and 
> saved), possibly relying on a default value for the new 'field' specified 
> in your Y-version model, maybe as part of a data migration?
>
> > So, I assume that the model state somehow is de-synced from the 
> database/migration state. I hop into the Django shell and check the model 
> metadata. The fields exactly match state Y. My database is still in state X.
> > Does that make sense?
>
> Makes perfect sense when you think about it. Being out of sync in this 
> manner happens constantly, and is exactly why migrations exist.
>
> Django makes the assumption that the current values in your models.py 
> files exactly match the layout of the DB, since you should be syncing 
> everything using migrations and validating via tests. 
>
> Any time you modify a model, the DB and you model definitions become out 
> of sync, with your models being 'ahead' of your DB since you haven't 
> informed the DB of your model changes via migrations yet. 
>
> Think of it like someone writing you a check. Your relative personal 
> wealth increases as soon as you receive the check, but your bank statement 
> won't agree with you until you submit the check to them so that they can 
> credit your account accordingly. 
>
> Feel free to write me a check (for a large amount, bigger the better) so I 
> can demonstrate the effect it has on my bank account. ;-)
>
> -James
>

On Thursday, October 1, 2015 at 1:17:43 AM UTC-7, James Schneider wrote:
>
>
> > I have tried that (by the way, the offending migration didn't show up in 
> the django_migrations table because the migration failed).
> >
> > I think we might be talking past each other. Sorry if I'm being unclear. 
> Here's an example of what's going on:
> > Before migration, my database is at state X, and my migrations files 
> reflect that.
> > I change my model file, updating the state (let's call it state Y). 
> Then, I run make migrations, generating a new migration file that 
> corresponds to state Y.
> > I run the migrate command to get my database to state Y. It fails, so 
> now my database is back at state X. There is nothing in the database to 
> delete (not even from the django_migrations table

Re: Corrupted Migration?

2015-10-02 Thread Daniel Chen
@Mike: I'm using Python 2.7.10 and Django 1.7. I'm not sure the ticket 
applies, but I appreciate the link!

@James: Sorry, I misspoke! [field] actually corresponds to a old field in 
state X. Before adding the new fields in state Y, the migration is trying 
to remove some old fields in state X but isn't finding them. I think this 
means that I'm unable to re-run that migration since it's looking for state 
X fields to remove, but can't find them (the model is already in state Y). 
My confusion is in the fact that the model state wouldn't roll back to 
state X after the first failed transaction (like the DB did).

This would be analogous to my writing you a check that will bounce. Once 
the check bounces, both your personal wealth and your bank statement should 
be back to what they were originally. But in this particular case, it looks 
like your personal wealth is stuck in a state that assumes the check has 
been cashed and your account has been credited, but your bank account 
disagrees :)

By the way, I talk about model state under the assumption that the Django 
ORM somehow internally keeps track of the models - I'm not sure exactly how 
it does this or if it does this at all. If you could tell me more about 
this, that'd be much appreciated!

On Thursday, October 1, 2015 at 1:17:43 AM UTC-7, James Schneider wrote:
>
>
> > I have tried that (by the way, the offending migration didn't show up in 
> the django_migrations table because the migration failed).
> >
> > I think we might be talking past each other. Sorry if I'm being unclear. 
> Here's an example of what's going on:
> > Before migration, my database is at state X, and my migrations files 
> reflect that.
> > I change my model file, updating the state (let's call it state Y). 
> Then, I run make migrations, generating a new migration file that 
> corresponds to state Y.
> > I run the migrate command to get my database to state Y. It fails, so 
> now my database is back at state X. There is nothing in the database to 
> delete (not even from the django_migrations table) because the transaction 
> was rolled back.
> > I delete the migration file that corresponds to state Y. My database is 
> back in state X, and my migration files again reflect that.
> > I run the migrate command again, and it fails (same problem). The error 
> is django.db.models.fields.FieldDoesNotExist: [Model] has no field named 
> [field].
>
> After you delete Y migration, have you searched your migration files to 
> verify that there are no references to that field?
>
> > [field] corresponds to a new field in state Y, not in an existing field 
> in state X. I'm confused - why is it looking for a field that doesn't exist 
> in the pre-migrated state (state X)?
>
> Do you have any RunPython or other custom modifications in your migrations 
> that would cause an object based on your modified model to be created (and 
> saved), possibly relying on a default value for the new 'field' specified 
> in your Y-version model, maybe as part of a data migration?
>
> > So, I assume that the model state somehow is de-synced from the 
> database/migration state. I hop into the Django shell and check the model 
> metadata. The fields exactly match state Y. My database is still in state X.
> > Does that make sense?
>
> Makes perfect sense when you think about it. Being out of sync in this 
> manner happens constantly, and is exactly why migrations exist.
>
> Django makes the assumption that the current values in your models.py 
> files exactly match the layout of the DB, since you should be syncing 
> everything using migrations and validating via tests. 
>
> Any time you modify a model, the DB and you model definitions become out 
> of sync, with your models being 'ahead' of your DB since you haven't 
> informed the DB of your model changes via migrations yet. 
>
> Think of it like someone writing you a check. Your relative personal 
> wealth increases as soon as you receive the check, but your bank statement 
> won't agree with you until you submit the check to them so that they can 
> credit your account accordingly. 
>
> Feel free to write me a check (for a large amount, bigger the better) so I 
> can demonstrate the effect it has on my bank account. ;-)
>
> -James
>

-- 
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/1ec20d88-1c82-4d28-9561-4065b2635288%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Corrupted Migration?

2015-10-02 Thread Mike Dewhirst

On 3/10/2015 8:35 AM, Daniel Chen wrote:

My confusion is in the fact that the model state wouldn't roll back to
state X after the first failed transaction (like the DB did).


No. The model is all your own work. Anything you write stays written. 
The migration system tries to implement your work. If it fails, it will 
roll the database back to its previous state. It does nothing to your 
work. You need to take note of the failure, decide how to fix your work 
and try again.


If you eliminate the error in your work (assuming no bugs in the 
framework) the migration will work and advance the database state to 
match the model state.


Mike

--
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/560F0DEC.7050401%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Corrupted Migration?

2015-10-02 Thread James Schneider
On Fri, Oct 2, 2015 at 3:37 PM, Daniel Chen  wrote:

> @Mike: I'm using Python 2.7.10 and Django 1.7. I'm not sure the ticket
> applies, but I appreciate the link!
>
> @James: Sorry, I misspoke! [field] actually corresponds to a old field in
> state X. Before adding the new fields in state Y, the migration is trying
> to remove some old fields in state X but isn't finding them. I think this
> means that I'm unable to re-run that migration since it's looking for state
> X fields to remove, but can't find them (the model is already in state Y).
> My confusion is in the fact that the model state wouldn't roll back to
> state X after the first failed transaction (like the DB did).
>

That makes even less sense than your original issue. Are you sure that
migration X was applied properly? What versions of migrations are stored in
your django_migrations table? Is the latest migration listed in there for
your app? You should be able to find it with a raw SQL statement, something
like "select * from django_migrations where app = '';".

Does [field] currently exist in your database so that it can be removed? If
not, you've had issues with migrations beyond this particular i

No. The model is all your own work. Anything you write stays written. The
migration system tries to implement your work. If it fails, it will roll
the database back to its previous state. It does nothing to your work. You
need to take note of the failure, decide how to fix your work and try again.
ssue. Were any migration files removed? Does the database match migration X?

Even better, can you also post the full traceback that you receive during
the failed migrations? That might lead to more clues.


>
> This would be analogous to my writing you a check that will bounce. Once
> the check bounces, both your personal wealth and your bank statement should
> be back to what they were originally. But in this particular case, it looks
> like your personal wealth is stuck in a state that assumes the check has
> been cashed and your account has been credited, but your bank account
> disagrees :)
>
>
Oh well, worth a shot. :-D


> By the way, I talk about model state under the assumption that the Django
> ORM somehow internally keeps track of the models - I'm not sure exactly how
> it does this or if it does this at all. If you could tell me more about
> this, that'd be much appreciated!
>

The ORM will use whatever model definitions contained within the models.py,
regardless of database state. It has no idea whether or not the equivalent
fields exist in the database (until an exception is thrown when the DB
returns an error accessing a missing field, etc.). Migrations are a process
completely outside and separate of Django running as an application via
runserver or a WSGI process. Migration files are the only files that would
keep versions of your models, and are not consulted at any time except
during migrations. So if you change anything in models.py, you should
create a new migration and apply it before doing any further development.

-James

-- 
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/CA%2Be%2BciUcG6aKH-Mfmoav62ThR%3D6yL5J2JJjE2DArE2mh0Uumhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Corrupted Migration?

2015-10-02 Thread James Schneider
>
> @James: Sorry, I misspoke! [field] actually corresponds to a old field in
>> state X. Before adding the new fields in state Y, the migration is trying
>> to remove some old fields in state X but isn't finding them. I think this
>> means that I'm unable to re-run that migration since it's looking for state
>> X fields to remove, but can't find them (the model is already in state Y).
>> My confusion is in the fact that the model state wouldn't roll back to
>> state X after the first failed transaction (like the DB did).
>>
>
> That makes even less sense than your original issue. Are you sure that
> migration X was applied properly? What versions of migrations are stored in
> your django_migrations table? Is the latest migration listed in there for
> your app? You should be able to find it with a raw SQL statement, something
> like "select * from django_migrations where app = '';".
>
> Does [field] currently exist in your database so that it can be removed?
> If not, you've had issues with migrations beyond this particular i
>
> No. The model is all your own work. Anything you write stays written. The
> migration system tries to implement your work. If it fails, it will roll
> the database back to its previous state. It does nothing to your work. You
> need to take note of the failure, decide how to fix your work and try again.
> ssue. Were any migration files removed? Does the database match migration
> X?
>
> Even better, can you also post the full traceback that you receive during
> the failed migrations? That might lead to more clues.
>

Whoops, looks like part of my response got wrapped around Mike's by
accident. Here's what it was supposed to say:

"That makes even less sense than your original issue. Are you sure that
migration X was applied properly? What versions of migrations are stored in
your django_migrations table? Is the latest migration listed in there for
your app? You should be able to find it with a raw SQL statement, something
like "select * from django_migrations where app = '';".

Does [field] currently exist in your database so that it can be removed? If
not, you've had issues with migrations beyond this particular issue. Were
any migration files removed? Does the database match migration X?

Even better, can you also post the full traceback that you receive during
the failed migrations? That might lead to more clues."

-James

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