Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pollyanna
Mar 5, 2005

Milk's on them.


Okay, I'm actually having some trouble now. I first tried Zinnia, but I ran into an issue where one of the modules it expected Django to have didn't exist (:confused:), so I tried to update Django. (I'm running in a venv now, so no worries) pip told me to upgrade it but then Django bitched about there already being an install, and told me to delete the sitepackages/django directory. I did that then tried to reinstall, but I can't because pip and easy_install say it's already installed. :byodood:

I might just wipe Django from my main installation and work from virtualenv from now on.

edit: Amazing. Mezzanine fucks up my installation too because it hasn't updated to 1.6. :tizzy:

Pollyanna fucked around with this message at 17:36 on Nov 8, 2013

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Maluco Marinero posted:

You don't need a model, you just need to actually load the form in the view, at the moment you aren't doing that. Have a read, haven't done everything inside form.is_valid, but this should be a start for you. It should now render in the template.

Python code:
from django.shortcuts import render_to_response
from django.template import RequestContext
from royals.forms import RoyalForm

from royals import mycode

def index(request):
    context = RequestContext(request)
    
    if request.method == 'POST':
        form = RoyalForm(request.POST)
        if form.is_valid():
            royal_text = form.cleaned_data['royal_text']
            skyv_url = mycode.find_url(royal_text) # Call to my script, which is located in the app's folder.
    
            #context_dict = {'skyv_url': skyv_url}
            return render_to_response('template.html', skyv_url)
    else:
        form = RoyalForm() # No Data, an empty form  
   
    # this is outside the if else, that way if the form is not valid it renders with the invalid data errors

    return render_to_response('royals/index.html', {"form": form}, context)

edit: formatting broke
Thanks, this worked. Additionally, I needed to change the form's inheritance from form.ModelForm to form.Form.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Pollyanna posted:

Okay, I'm actually having some trouble now. I first tried Zinnia, but I ran into an issue where one of the modules it expected Django to have didn't exist (:confused:), so I tried to update Django. (I'm running in a venv now, so no worries) pip told me to upgrade it but then Django bitched about there already being an install, and told me to delete the sitepackages/django directory. I did that then tried to reinstall, but I can't because pip and easy_install say it's already installed. :byodood:

I might just wipe Django from my main installation and work from virtualenv from now on.

edit: Amazing. Mezzanine fucks up my installation too because it hasn't updated to 1.6. :tizzy:

1.6 is hot off the presses, you may want to stick with 1.5.5 for now until the libraries have a chance to catch up.

I've never had to manually delete anything from sitepackaegs, not sure what happened there. What module was it complaining about Django missing? Copy/pasta the exact errors in here, somebody will be able to help you out.

It sounds like maybe Django is installed outside of your virtualenv? Run deactivate to get out of your venv, then you should be able to do pip uninstall django to get rid of it.

Otherwise you can tell venv to ignore those packages when you create your venv by using --no-site-packages. You don't even have to install Django in your venv before installing mezzanine, since mezzanine lists all the dependencies it needs, pip will automatically install the right versions of them:

code:
greg@mint $ virtualenv --no-site-packages mezz_test
greg@mint $ source ./mezz_test/bin/activate
(mezz-test)greg@mint $ pip install mezzanine
...
...
Successfully installed mezzanine django filebrowser-safe grappelli-safe html5lib bleach pytz requests requests-oauthlib pillow oauthlib
Cleaning up...
(mezz-test)greg@mint $

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Dominoes posted:

Thanks, this worked. Additionally, I needed to change the form's inheritance from form.ModelForm to form.Form.

Ah yep, didnt see that. ModelForm is only for when you want a form to automatically generate from a database model defined in models.py.

Dominoes
Sep 20, 2007

Has anyone gotten Django working on OpenShift? The tutorials I find lead to HTTP 403 errors.

For example, if I follow this tutorial, the rhc tail dump is as follows:

code:
  
==> python/logs/appserver.log <==
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 869, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "wsgi/application", line 8, in <module>
    virtenv = os.environ['APPDIR'] + '/virtenv/'
File "/var/lib/openshift/528280414382ecf87b0000ca/python//opt/lib/python3.3/os.py", line 669, in __getitem__
    value = self._data[self.encodekey(key)]
KeyError: b'APPDIR'
A fellow at this website fixed this error by changing a line in the application file: virtenv = os.environ['OPENSHIFT_HOMEDIR'] + '/virtenv/'

The resulting tail dump:
code:
==> python/logs/appserver.log <==
    return _LoadSourceCompatibility(name, pathname, file).load_module(name)
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 869, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "wsgi/application", line 14, in <module>
    execfile(virtualenv, dict(__file__=virtualenv))
NameError: name 'execfile' is not defined
Based on this stack overflow thread, I changed the offending line to exec(compile(open(virtualenv).read(), virtualenv, 'exec'), dict(__file__=virtualenv))

New tail dump:
code:
==> python/logs/appserver.log <==
    signals.request_started.connect(reset_queries)
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/dispatch/dispatcher.py", line 88, in connect
    if settings.DEBUG:
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/conf/__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/conf/__init__.py", line 132, in __init__
    % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'PROJECTNAME.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'PROJECTNAME'

Edit: got a template working by changing 'PROJECTNAME' to my project name. However, when I try to apply it to my existing Django project, I get a 503 with tail:
code:
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'myproject'
The application.py files and openshift-related directory structure of the working template and broken project seem similar. There's definitely a myproject.settings.py file where it should be.
edit a

Dominoes fucked around with this message at 21:49 on Nov 12, 2013

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I want to create tens of thousands of model instances as fast as possible. Actually in not completely impossible cases it could be millions.

This would be from what I guess you could call out of band scripts that import the models and create instances and save them.

Anyone have any experience doing this?

My first inclination is to use green threads, but I'm not sure how Django deals with concurrent writes.

I'd also like to figure out a way to get Django to use a pool of database connections instead of creating a new connection for each model creation which I think is what it does now.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Just write raw SQL for the importing at this point. The ORM is holding you back.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Thermopyle posted:

I'd also like to figure out a way to get Django to use a pool of database connections instead of creating a new connection for each model creation which I think is what it does now.

I'd also suggest raw SQL like Suspicious Dish suggested. And use something like PGPool or PGBouncer as a connection pool for Django. Django 1.6 provides persistent connections per process, so that'll help too.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Dominoes posted:

Has anyone gotten Django working on OpenShift? The tutorials I find lead to HTTP 403 errors.

Have you looked at https://github.com/openshift/django-example ?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Raw SQL it is. Thanks dude(ttes)

Dominoes
Sep 20, 2007

Yea - that version doesn't even get past the APPDIR problem. This is getting weird, and I can't figure out why some test projects I'm creating work and others 503 with the import error. Ie: If I start a clean django project in my app's wsgi directory, it works. If I copy and paste it, and change the project name in all of the basic django files, and in the application file, it works. If I name is the same thing as the project I actually want to use as a step prior to pasting the code in, it doesn’t. I'd use Heroku, which just works, but I think my work's firewall doesn't block openshift apps, but does block heroku apps.

Dominoes fucked around with this message at 14:59 on Nov 13, 2013

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Try #openshift on Freenode?

avidal
May 19, 2006
bawl-some

Thermopyle posted:

I want to create tens of thousands of model instances as fast as possible. Actually in not completely impossible cases it could be millions.

This would be from what I guess you could call out of band scripts that import the models and create instances and save them.

Anyone have any experience doing this?

You could also use Model.objects.bulk_create and pass it a list of unsaved model instances. Build them up to some specified size (based on benchmarking) and then run the bulk_create call. Django will turn it into a single INSERT statement with multiple VALUES clauses.

MonkeyMaker
May 22, 2006

What's your poison, sir?

avidal posted:

You could also use Model.objects.bulk_create and pass it a list of unsaved model instances. Build them up to some specified size (based on benchmarking) and then run the bulk_create call. Django will turn it into a single INSERT statement with multiple VALUES clauses.

The "unsaved model instances" are all stored in memory, though. Not sure you'd want potentially millions of objects in memory.

Dominoes
Sep 20, 2007

Suspicious Dish posted:

Try #openshift on Freenode?
Turns out Openshift needs the path for templates to be os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir).

TangoWithDjango demonstrates cwd, which is what was screwing it up. It has to do with Openshift's nested directory structure.


Here's an example working application file:

Python code:
#!/usr/bin/python
import os, sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'modulenamegoeshere.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',
    'modulenamegoeshere'))

virtenv = os.environ['OPENSHIFT_HOMEDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python3.3/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')

try:
    exec(compile(open(virtualenv).read(), virtualenv, 'exec'), dict(__file__=virtualenv))
except IOError:
    pass

#
# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
#
from django.core.handlers import wsgi
application = wsgi.WSGIHandler()
The virtenv assignment has been changed from the outdated official instructions, and the exec line has been changed for Python3 compatibility.

Hed
Mar 31, 2004

Fun Shoe
A few months ago some big Python/Django person wrote a blog post about integrating AngularJS into their Django apps. Does anyone know what I'm talking about and have a link? I'm at a loss.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
For those of you that use virtualenv-burrito, is there any reason I wouldn't want to source /home/fletcher/.venvburrito/startup.sh automatically when a shell is opened? Is ~/.bashrc the right place for that kind of thing?

ufarn
May 30, 2009

Hed posted:

A few months ago some big Python/Django person wrote a blog post about integrating AngularJS into their Django apps. Does anyone know what I'm talking about and have a link? I'm at a loss.
Try one of these submissions: https://www.hnsearch.com/search#request/submissions&q=django+angularjs&start=0.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
What are some good libraries to look at for caching models and querysets? django-cache-machine looks pretty nice. Or should I just use the low level caching API built into Django and just cache a few specific things here and there?

MonkeyMaker
May 22, 2006

What's your poison, sir?
I've never had a problem with johnny-cache.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
It's safe to leave django-debug-toolbar in INSTALLED_APPS and MIDDLEWARE_CLASSES on production right? I know it's not supposed to do anything when DEBUG = False but I just wanted to double check.

jony neuemonic
Nov 13, 2009

What are peoples' thoughts on PythonAnywhere? It seems like an affordable enough PaaS if you don't mind getting your hands a bit dirty.

evilentity
Jun 25, 2010
Are there any decent tutorial kind of things? Ive done the official pools one, and i like what ive seen. Ive used various unclean web stuff before, but im nowhere near experienced. Django book looks awfully outdated at this point. My endish goal is small ecommerce kind of site if that changes anything.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

evilentity posted:

Are there any decent tutorial kind of things? Ive done the official pools one, and i like what ive seen. Ive used various unclean web stuff before, but im nowhere near experienced. Django book looks awfully outdated at this point. My endish goal is small ecommerce kind of site if that changes anything.

The book Two Scoops of Django might be a good place to go after the official tutorial, or maybe Test Drive Web Development with Python (look for the free version link on that page).

jony neuemonic
Nov 13, 2009

Thermopyle posted:

The book Two Scoops of Django might be a good place to go after the official tutorial, or maybe Test Drive Web Development with Python (look for the free version link on that page).

Two Scoops might be a bit advanced depending on how comfortable you are with Python. Tango With Django fit nicely between the official tutorial and Two Scoops for me.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

fidel sarcastro posted:

Two Scoops might be a bit advanced depending on how comfortable you are with Python. Tango With Django fit nicely between the official tutorial and Two Scoops for me.

Yeah, you might be right.

Two Scoops came out after I was more advanced with Django, and it's kind of hard to slot that in to my what-did-i-understand-at-what-stage model.

Anyway, I think people should read Two Scoops once they can understand what's going on it. I think MonkeyMaker recommended it at some point in here originally...

jony neuemonic
Nov 13, 2009

Thermopyle posted:

Anyway, I think people should read Two Scoops once they can understand what's going on it. I think MonkeyMaker recommended it at some point in here originally...

Agreed. It's an excellent book.

evilentity
Jun 25, 2010
Im quite comfortable, ill check out all 3 books, cheers.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm playing around with django-mptt and I want cheap access to len(node.get_children()) so I don't have execute N queries to get the children count of N nodes. Any suggestions for how to go about this? I was thinking I might have to just add a children_count field on the model and calculate it in a cron job that runs in the background. I don't need this value to always be up to date, it's fine if there is a bit of a delay on it.

I started going down the route of trying to cache the serialized response data to at least reduce the frequency that those N queries get executed, but it started to feel not quite right.

edit: Nevermind, I just shoved it in memcached and called it a day. Don't want to spend forever trying to optimize this just yet.

fletcher fucked around with this message at 23:48 on Dec 5, 2013

Pollyanna
Mar 5, 2005

Milk's on them.


I'm trying to model a Log using ORM, and I'm a bit confused on how. I want to make a log object with four individual parts, each with its own set of fields (some with text input, some with character input and associated integers). So far, I've managed to define a log object and two of the four steps. Is this approach correct? Will this end up with a log in several parts, or something totally different? How do I make it so the second step can hold multiple feeling attributes and associated integers?

EDIT: Changed the code. It's different now. Still asking for advice...

Python code:
from django.db import models


class MoodLog(models.Model):
    # Each mood log has an associated date.

    publish_date = models.DateTimeField(auto_now=True)

    # Step one: Identify the upsetting situation.
    # One large text entry field.

    event = models.TextField(max_length=300, unique=True)

    # Step two: Record negative feelings.
    # More than one feeling can be created.
    # Each feeling is associated with a single integer from 0-100.

    feeling = models.CharField(max_length=30, unique=True)
    rating = models.IntegerField

    def __unicode__(self):
        return self.name

Pollyanna fucked around with this message at 01:56 on Dec 6, 2013

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Pollyanna posted:

I'm trying to model a Log using ORM, and I'm a bit confused on how. I want to make a log object with four individual parts, each with its own set of fields (some with text input, some with character input and associated integers). So far, I've managed to define a log object and two of the four steps. Is this approach correct? Will this end up with a log in several parts, or something totally different?

Python code:
from django.db import models


class MoodLog(models.Model):
    # Each mood log has an associated date.

    publish_date = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return  self.name

I don't quite understand your problem, but your Unicode methods are going to have a hard time finding the non-existent name' property.


As to your problem, are these four distinct Log objects that are related, or a single Log object that will have its properties set at different times? If the former, I would create a Log object that has four LogPart properties on it, and then have subclasses of LogPart for the individual bits. If the latter, just put al the properties on it and have them be optional, then populate them over time.

EDIT: I replied befor your edit, so seems like you are going for the latter.

Pollyanna
Mar 5, 2005

Milk's on them.


Lumpy posted:

EDIT: I replied befor your edit, so seems like you are going for the latter.

Yup, that's it. This is the model for the, uh...model. What I'm stuck on right now is having multiple feeling attributes at the same time, and each one having an associated integer. Is there an equivalent for a dictionary in this case...?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I think something like this might also work. Basically since you want each MoodLog to be able to have multiple Feeling & Rating combos associated with it, those could be their own model, with a key that points back to the MoodLog they are associated with. Django then makes it easy to query the relationships between these tables.

Python code:
class Feeling(models.Model):
    name = models.CharField(max_length=100)


class MoodLog(models.Model):
    publish_date = models.DateField()
    event = models.CharField(max_length=100)


class MoodLogEntry(models.Model):
    moodlog = models.ForeignKey(MoodLog)
    feeling = models.ForeignKey(Feeling)
    rating = models.IntegerField()
Now in python manage.py shell (or Admin UI) you can create some test data:
code:
>>> from moodlogger.models import *
>>> bad = Feeling.objects.create(name='Bad')
>>> sad = Feeling.objects.create(name='Sad')
>>> mad = Feeling.objects.create(name='Mad')
>>> glad = Feeling.objects.create(name='Glad')
>>> rad = Feeling.objects.create(name='Rad')
Create a MoodLog:
code:
>>> mylog = MoodLog.objects.create(publish_date='2013-12-05', event='First snowboarding backflip')
Create a couple MoodLogEntry records for mylog:
code:
>>> MoodLogEntry.objects.create(moodlog=mylog, feeling=glad, rating=75)
<MoodLogEntry: MoodLogEntry object>
>>> MoodLogEntry.objects.create(moodlog=mylog, feeling=rad, rating=100)
<MoodLogEntry: MoodLogEntry object>
Want all the feelings associated with a particular event? (Django created this *_set automatically because of our moodlog ForeignKey in the MoodLogEntry model)
code:
>>> for entry in mylog.moodlogentry_set.all():
...     print('Feeling: %s, Rating: %d' % (entry.feeling.name, entry.rating))
...     
Feeling: Glad, Rating: 75
Feeling: Rad, Rating: 100

Pollyanna
Mar 5, 2005

Milk's on them.


Dang, that kinda makes sense. I changed yours around a bit, here's what I got:

Python code:
from django.db import models


class Feeling(models.Model):
    name = models.CharField(max_length=100)
    rating = models.IntegerField()


class Thought(models.Model):
    text = models.TextField(max_length=300)
    belief = models.IntegerField()


class MoodLog(models.Model):
    # Each mood log has an associated date.

    publish_date = models.DateTimeField(auto_now_add=True)

    # Step one: Identify the upsetting situation.
    # One large text entry field.

    event = models.TextField(max_length=200, unique=True)

    # Step two: Record negative feelings.
    # More than one feeling can be created.
    # Each feeling is associated with a single integer from 0-100.

    negative_feeling = models.ForeignKey(Feeling)

    # Step three: Triple-column technique.
    # This is a table...kinda tricky.
    # One column is "automatic thoughts" of thought:rating associations.
    # Second column is "distortions", all text fields/charfields. (Maybe add a dropdown list?)
    # Third is a repeat of column 1, but with different key-value pairs.

    automatic_thought = models.ForeignKey(Thought)

    distortion = models.CharField(max_length=40)

    revised_thought = models.ForeignKey(Thought)

    # Step four: How do you feel now?

    purest_feeling = models.TextField(max_length=300)

    def __unicode__(self):
        return unicode(self.publish_date)
Syncing the DB gives me this error, though:

code:
CommandError: One or more models did not validate:
logs.moodlog: Accessor for field 'automatic_thought' clashes with related field 'Thought.moodlog_set'.
Add a related_name argument to the definition for 'automatic_thought'.
logs.moodlog: Accessor for field 'revised_thought' clashes with related field 'Thought.moodlog_set'.
Add a related_name argument to the definition for 'revised_thought'.
What am I missing? I thought I was just defining what a Thought was and making a few different instances of them. Is that not possible...?

Also, is there an easier way to mess around with models without having to destroy and recreate your database? :(

edit: Aha! I needed to add a related_name for each individual Thought.

Python code:
    automatic_thought = models.ForeignKey(Thought, related_name="automatic")
etc

Pollyanna fucked around with this message at 04:51 on Dec 6, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
edit: hah you beat me :)

Pollyanna posted:

Syncing the DB gives me this error, though:

code:
CommandError: One or more models did not validate:
logs.moodlog: Accessor for field 'automatic_thought' clashes with related field 'Thought.moodlog_set'.
Add a related_name argument to the definition for 'automatic_thought'.
logs.moodlog: Accessor for field 'revised_thought' clashes with related field 'Thought.moodlog_set'.
Add a related_name argument to the definition for 'revised_thought'.
What am I missing? I thought I was just defining what a Thought was and making a few different instances of them. Is that not possible...?

Also, is there an easier way to mess around with models without having to destroy and recreate your database? :(

Since you have multiple foreign keys to Thought, Django is getting confused when it tries to create that *_set accessor, because they all end up with the same default name. Fortunately Django lets you specify a name, so they don't clash.

Simplest way is to fix it is to tell Django not to create those *_set accessors, but doing:
Python code:
automatic_thought = models.ForeignKey(Thought, related_name='+')
revised_thought = models.ForeignKey(Thought, related_name='+')
So if you want all the MoodLogs where your automatic_thought is Happy:
Python code:
MoodLog.objects.filter(automatic_thought=Feeling.objects.get(name='Happy')).all()
Or if you do want those accessors (they can be handy, depending on how you are querying your data):
Python code:
automatic_thought = models.ForeignKey(Thought, related_name='moodlog_automatic_thoughts')
revised_thought = models.ForeignKey(Thought, related_name='moodlog_revised_thoughts')
Then you could find all the MoodLogs where your automatic_thought is Happy going the other way:
code:
Feeling.objects.get(name='Happy').moodlog_automatic_thoughts.all()

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
As far as not having to blow away your DB when you are playing around, you could use something like South. I find myself using the "iteratively working on a migration" workflow a lot when I'm playing around with things.

You don't have to use that though, you could simply just make a little python script that creates all your data, so after you blow away your database you can just run your little "generate some data" script.

Pollyanna
Mar 5, 2005

Milk's on them.


Suh-weet. Got it working. Except for one thing...

In the admin interface, I expected it to have a char and integer field when I go to edit automatic/revised thoughts, but instead it looks like this:



I'll prolly have to go digging into changing the admin interface, but at least the models are working.

Also, I'm not sure how to add more negative feelings to an associated log, or at least I don't know how to get that to show up on the admin site.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Pollyanna posted:

Suh-weet. Got it working. Except for one thing...

In the admin interface, I expected it to have a char and integer field when I go to edit automatic/revised thoughts, but instead it looks like this:



I'll prolly have to go digging into changing the admin interface, but at least the models are working.

Also, I'm not sure how to add more negative feelings to an associated log, or at least I don't know how to get that to show up on the admin site.

Have a look in the admin documentation. The thing you're looking for is admin.TabularInline.

Pollyanna
Mar 5, 2005

Milk's on them.


Maluco Marinero posted:

Have a look in the admin documentation. The thing you're looking for is admin.TabularInline.

All my attempts at getting that to work ended in failure. I'm moving to the original setup for now :negative: but I still want to fix this eventually.

Adbot
ADBOT LOVES YOU

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Pollyanna posted:

All my attempts at getting that to work ended in failure. I'm moving to the original setup for now :negative: but I still want to fix this eventually.

Show me your current admin code and I'll see how I can help.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply