retrieving variable from intermed table - django

I need to retrieve institution name by going through an intermediate table. My view gets all the values except this one or at least it is not displaying in the template. Can someone please help with either revising my view or template statement?
http://dpaste.com/122204/
Thank you,
May

To debug these kinds of problems do the following.
Run the view function's processing separate from any template or any other parts of Django.
Either interactively or with a VERY simple script run your query. For example, use a simple script like this to explore your model and make sure your model really works.
from app.models import Contact, Institution, Whatever
results= Researchproject.objects.filter(restitlestrip__icontains='something').distinct()
for project in results:
print project.contact
print contact.institutionname
Note several things about your simple script and your template.
Case matters. Project != project.
Navigation matters. In the script shown above, contact is undefined. project.contact, however, is defined. Perhaps that's what you meant.
Your model appears incomplete. The Contactintermed table doesn't seem to be used anywhere in your query or view. It may have FK's to other tables, but you don't seem to have a sensible navigation from Project through Contact to Contactinterma to Institution.
Get your model to be correct in a stand-alone script. Add the template processing later.
Also, please post all the code here on StackOverflow. Chasing your code down all over the internet is a huge pain. It's far easier to simply ignore your question than it is to chase down your code.

Related

Update a template in my Template Gallery externally

I have a template in my template gallery that I have been working on and have hit something of a snag with what I am wanting to do. Basically, I want to have my invoice numbers increment when I click on the graphic button in Column H. I have a script tied to the drawing and it works exactly how I want it to--at least locally.
So, here is my question: I would like to have this script update the data sheet on my template--either in addition to or instead of--I don't really care either way on that.
EtA: I neglected to include a link to an example sheet. Here is that:
https://docs.google.com/spreadsheets/d/17zOSkM2yYSMOKobgKkkhQNHHRR901gBiK0BdeempZwo/edit?usp=sharing
Honestly, I haven't really attempted anything. The sum total of my looking into this has been looking via Google and in the forums, but everything I'm finding talks about being able to pull data from an external spreadsheet, but nothing about pushing data there. Given that this is a template. An alternative (in my mind) would be to have the invoice number automatically increment/set each time the template is used, but I have no idea where to even start on something like that.
Any advice--even telling me that I am out of my gourd and nothing like this is possible using Google Sheets--is appreciated.

Should I use a constraint?

I'm developing a Twitter-like system, and have a model to record who follows who. There are two fields and both fields are foreign keys and point to the User model.
Clearly you wouldn't want a follower-followee record duplicated, so I'm using the unique_together attribute in the inner Meta class, in order that the follower-followee pair is unique. Trying to violate this throws IntegrityError and 500 status code.
This feels like a "second line of defence" as my view and template code doesn't give a user the chance to follow someone twice.
Should I/can I do something similar to ensure you can't follow yourself?
The view and template that lists all users (each with a button to click to follow that user) does not list the currently logged in user, so there should be no opportunity to follow yourself. But I don't have anything equivalent to unique_together.
Dude, no.
I don't know why you're doing this, but assuming it isn't for a uni project with a lunatic professor, you're wasting your time.
That is, if he's not a lunatic he's not going to try and hack the following/followee . And so what if he does?
If its for a startup-idea, then spend less time solving this (trivial) problem and more time working on whatever business model or marketing or whathaveyou thing you need to do.
A little bug isn't going to be a show stopper.
If you're being contracted out, leave it as a bug and get the conteact extended to fix it :)
If you just want to fix this, just do a check in the model or the validation that the follower isn't the same as the followee

Satchmo: list all active products

I'd like to list all active products (from all or a specific category) in a template. I've looked almost everywhere and I simply cannot find a way to do this.
I want to display them in the footer of the shop (10 products from 1 category). That means show them without selecting product category.
Is this even possible? Products are only listed in the category template...
I'm using Satchmo 0.9.2
EDIT: Somehow I've missed this:
http://www.satchmoproject.com/docs/dev/customization.html
So it's solved...
Thank you!
this is a more general answer since there isnt any answer yet, so dont beat me. You also have to know that I never used satchmo, I never had a look at it.
But despite this, if I had to deal with your situation, I would have a look at the source code.
You might find answers there to develop something custom for your situation. This can be a tricky task but at least its worth a try.
There have to be models which store the data for your product and categories. Have a look at them and the views that retrieve the products from the database to render them. Also a look into the database cant hurt (think of phpmyAdmin to have a nice webbased interface).
It can be helpful to fire up your ./manage.py shell, import your/satchmos product and category models and play around with them.
A possible solution then could be to write a custom context_processor which retrieves the needed products/categories and passes these products from a category to your footer on a more global basis. Have a look here https://docs.djangoproject.com/en/1.3/ref/templates/api/#writing-your-own-context-processors. Maybe a custom middleware could also be a possibility. https://docs.djangoproject.com/en/dev/topics/http/middleware/#writing-your-own-middleware
I hope this helps. At least worth a try :)

Data structure for changing form using Django Models and Admin app

I am writing a Django application and using the built-in ORM. I would like to create functionality to provide a form but the template for that form needs to be built on admin side of the application and can change over time.
For instance, initially they have a form that asks for first name, last name but later if they decide to add birthday field admin should be able to go to this template page add birthrate as new field and on client side, users start seeing it. Is there anything already in place that can be used? I was thinking of using something like this but decided to check here and see if there is something better available.
Is it this what your are looking for?
I have never heard about any library for that, because you have pretty much different approaches to handle that!, but check the link, he is explaining better those approaches.

Django and Generic Views

I've written an entire app pretty successfully in Django but I have this nagging question that I think I know the answer to but I just want to make sure.
One of the things I really liked about Django was the data model and the ability to not have to do "obvious" stuff. For example, we use the admin interface extensively in our app. The fact that I don't need to write an edit screen for every model and keep it up to date every time the model changes is really nice.
What I'm puzzled by is that I wanted to have one part of the app render "read-only" versions of the models. Essentially I want exactly what I have in the Admin interface but without editable widgets. Now I notice, from the Django code, that that admin interface actually goes through and substitutes the widgets to use the editable ones so I know that non-editable is certainly there.
But as far I can tell, there is no way to just say "render this object" and have Django do the "obvious" thing and render it just like it does for the admin interface but with non-editable fields. I find this hard to believe since it seems like a) this is easier than the admin stuff and b) I know the widgets are already there. But I've looked all over and even the Django examples seem to always create a template and spell out exactly what the page should look like.
Writing a template is probably a good idea in general but early on in development when things are changing it would be better to have something that just does something basic given the information available in the model.
Am I missing something? Sorry if this is a stupid question.
Could be that most non-toy sites want a custom layout/html anyway?
Or, are you looking for Databrowse?
I used something like this: http://www.djangosnippets.org/snippets/937/
There are other similar things around if you google for 'django read-only admin' or similar.
Never underestimate how flexible the Django Admin is...