In my application I have Domain model that have these columns: name, link, description.
Currently my application works as I can only add one domain at a time (from new action). What I am looking for is to be able to add as many domains as I want from the same form/page.
I have used nested_forms before but usually its nested_attributes for another model.
How am I able to have nested_forms for same model or if there is any other way?
This can be done, but not in a RESTful way. There are some hacks to do it, But I don't recommend and best way would be to do associations and adding nested_attributes to it.
Related
I'm building a backend with some core-functionality app (which means, of course, a single DB for the app).
I'm looking for elegant way to create app for every new customer by "copying" some template (basic) app to be able modify every's customer app with specific customer's requirements.
For ex., I have some basic StoreApp in Django. It could have some basic features, models etc. Now, when some new customer wants to sign up, I want dynamically (not manually) create additional copy of the existing StoreApp (of course, under different name and its own DB), make initial migration for it, register it in the settings and so on. Lately, I want to customize this new app according to the customer's requirements. I'm just looking for a way to separate code maintenance for every existing app, but, as I mentioned before, not to create every app manually.
Any elegant way to do it? Some existing plugin for Django?
Thanks in advance,
Efi
In my project I need to add a lot of custom entities to Typo3 CMS.
Eg. I need to have Buildings, Building Companies, Architects, Certifications, and so on.
What is the common approach for doing this?
Should I develop a new extension?
How can I then have a custom backend for managing these entities? Eg. in the Buildings admin page I want to be able to add a new Building also associating one or more Architects to it. Is it feasible? How?
Can I create a custom backend field for looking up Architects in the Buildings admin page? (eg. something like StackOverflow tags system, a token input field which looks up for items in Architects table in real-time while editing a Building)
To map a business model into Typo3 I prefer to build an extension for that.
On the one hand you have the maximum flexibility by programming in PHP with the help of the Typo3 framework and on the other hand most of the backend management pages come in easy when using the standard MVC + TCA structure of Typo3 Extbase extensions (if it is your first try with Extbase you might want to have an Extbase book at hand).
You can have a look at the Typo3 TCA page to see which standard backend field types are available - there are shown a lot of example configurations. As in your case you might want to use a select field with property "size" > 1 and property "maxitems" > 1 to describe the relation between buildings and architects. As for the architects filter feature you might also want to add the property "enableMultiSelectFilterTextfield" as shown in this example.
I'm new to Ember.js but I decided to try it for my task.
The task is to make a dynamic form builder: user should be able to add boxes with names and then insert field configs (which are forms) into that boxes.
Field configs are editable and they should be saved after edit.
In the backend I use Rails+AMS+Mongo and the data structure looks like that:
Company has one UsersProfileConfig
UsersProfileConfig has many BoxConfigs
BoxConfig has many FieldConfigs
In Ember I've already created models for BoxConfigs and FieldConfigs and basic routes for them.
Now I feel stuck and don't know what to do next and whether it was a good idea to use Ember for that.
Could anyone suggest me workflow or next development steps?
I am interested in setting up my application so that I can serve location specific content.
Something like craigslist, where miami.craigslist.org only shows posts in miami.
Assuming that I have a model that has a City field, what would be the best way to achieve this?
Banjer suggested the Sites framework, but I feel like it might not be a 100% perfect fit for your situation. The sites framework works well for different sites sharing the same database. But in your case, its all the same site and you are basically just wanting to pass an argument to your views for the city.
You could probably do something even simpler by just pointing wildcard *.domain.com to your django site, and then using request.get_host() in the view to parse out the subdomain:
https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest.get_host
So if the domain were: "losangeles.domain.com", and you parsed out "losangeles", you could use that as your city "tag" in your query. And when you create new content, you can just tag it with a city.
Post.objects.filter(city_tag="losangeles")
I suppose it depends on how robust of a "location" structure you need in your site. It very well might be a City model with various meta data fields, including the tag field. Then you would associate it with the content as a foreign key. It kind of approaches the same general idea as the Sites framework, but in this case you aren't really creating different sites.
You should check out the "sites" framework. If you've ever used the built-in Django admin, then you've probably seen the sites section where example.com is the only site listed by default.
Real world example, from the link I provided:
Associating content with multiple sites
The Django-powered sites LJWorld.com and Lawrence.com are operated by
the same news organization – the Lawrence Journal-World newspaper in
Lawrence, Kansas. LJWorld.com focuses on news, while Lawrence.com
focuses on local entertainment. But sometimes editors want to publish
an article on both sites.
The brain-dead way of solving the problem would be to require site
producers to publish the same story twice: once for LJWorld.com and
again for Lawrence.com. But that’s inefficient for site producers, and
it’s redundant to store multiple copies of the same story in the
database.
The better solution is simple: Both sites use the same article
database, and an article is associated with one or more sites.
So instead of a City field, you'd add a field to your model for Site, e.g.:
sites = models.ManyToManyField(Site)
You basically have one database that all of your cities use. Convenient, but I'm wondering how it would scale down the road. I'm starting a similar project myself and will use the Django sites framework to get the project off the ground. I'm interested in hearing about a more scalable solution from a database person though.
I have seen various questions on multi-site and multi-host Django, including subdomains and specific schemas per subdomain. What I have not seen is a solution (or tips so I can code one) to this problem.
I am using Django + PostgreSQL on a site, let's say myapp.com
The main site myapp.com is used for registration of companies
A registered company gets its own subdomain, company.myapp.com, and logs in and works from there.
My idea of doing this is by making 2 initial schemas in PostgreSQL.
Schema "auth" for companies and users
Schema "empty_company_template" with the basic tables for a company, all empty but hooked up to the right sequences etc.
When a new company registers, I want this to happen:
Create a new schema for the company, derives from empty_company_template
Create a new DB user for the company, named company (the company name)
Set the search path for this new user to company, auth (no access to empty_company_template, no access to other users schema's)
To me this seems better than the existing solutions that all seem to depend on one single database user for the entire application (with access to all schemes). However, I struggle to get this to work. Is this indeed a viable approach? Can anyone point me in the right direction? It's Django, so perhaps it's been done and I just haven't found it?
I have a working solution that does everything except separate users.
It's a small piece of middleware (just process_request) that determines the subdomain, and executes a SET search_path query on the database. It's good enough for me for now.
Anyone interested in the code, just contact me. I'll publish it somewhere when it's final.
EDIT Dec 22, 2010:
I published the code on my blog at
http://blog.dyve.net/django-subdomains-and-postgresql-schemas
If you want to have separate DB users, you'll probably want separate Django instances, otherwise there will be no security gain. This model will require much more complicated process management. I don't think you'll find a ready-made solution for such an application, so you will most probably have to roll your own. Otherwise, if you're unwilling to invest much time, stick with the one user for the entire app approach.