I have a self referencing model like this:
class Item(models.model):
parent = models.ForeignKey('Item',null=True,blank=True)
field = models.CharField(max_length=100)
And I want to display the hierarchy in the admin, to do so I do:
class ItemInline(admin.TabularInline):
model = Item
can_delete = False
class ItemAdmin(admin.ModelAdmin):
inlines = (ItemInline,)
admin.site.register(Item, ItemAdmin)
However it does not work , when I try to acces an item in the admin it hangs endlessly but it I can access the list of items just fine.
However when I remove the inline it works fine.
Ok the issue i was facing was due to the fact I tried to display the whole object , by restricting the fields displayed it worked.
I did it like this : Django - Excluding some fields in Inline Admin Interface
Related
I have a grails application that takes user input (create page/method), the user then clicks a Save button (save method that executes service) and then the results are displayed (list method) on a page, for example http://localhost:8080/myApp/myclass/save.
The users would like each results run to be saved to a unique URL so they can share it, bookmark it, save it later, whatever. I have NO idea how to go about this and google searches turn up little to nothing.
For example an application run would result in the data being displayed at http://localhost:8080/myApp/myclass/systemname/datetimestring/someuniquedata/
Is this even possible? Any pointers GREATLY appreciated.
EDIT
Here is my urlMappings contents.
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/" {
controller = "api"
action = "create"
}
"500"(view:'/error')
}
}
When I display the results it's done through the list method shown here.
def list(Integer max) {
List<Api> api = Api.findAllBySessionId(session.id, [sort:'dateCreated'])
api = api[-2..-1]
[apiInstanceList: api, apiInstanceTotal: api.size()]
}
So I have the unique session ID. How do I need to modify "mappings"?
Every domain object that you're saving will have an autogenerated ID (assuming you're using GORM, which is definitely likely). It sounds like all you're asking for is a /show/id page where you can access a particular object via ID.
A url mapping for "/$controller/$action?/$id?" is a pretty straightfoward way to handle this, and is provided by default (and used by scaffolded controllers also).
If you'd rather not use an autogenerated ID (maybe you're moving objects from one database to another, or updating the ID for some reason?) you can consider using java.util.UUID.randomUUID() to generate a random, unique identifier and save that as a field on your object. You could then use .findByUuid with the input parameter.
I am creating a Libreoffice Base with multi forms. Form1 is linked to "Projects" table and each Project has multiple tasks, I can display the tasks as sub form within the same Form1, however, each project has many tasks and each task also has sub tasks so I want to have the tasks be in their own form, lets call it Form2.
I created a push button in Form1 that will open Form2, however, I don't know how to make it open that form and only display the tasks that are related to the project that was being displayed while pressing the push button.
So far here is what I have been able to do:
Reading the projectID which I want to display the tasks for (it is in a textbox called txtProjectID inside Form1):
Doc = StarDesktop.CurrentComponent
Form = Doc.DrawPage.Forms.GetByIndex(0)
ProjID = Form.getByName("txtProjectID").Text
To open the tasks form Form2 i found two ways:
Dim Args(1) As New com.sun.star.beans.PropertyValue
Args(0).Name = "ActiveConnection"
Args(0).Value = Form.ActiveConnection
Args(1).Name = "OpenMode"
Args(1).Value = "open"
oForm = thisComponent.Parent.getFormDocuments
oForm.loadComponentFromURL("Form2","_blank",0, Args())
and
oForm = ThisDatabaseDocument.FormDocuments.getByName("Form2")
oForm.Open
both works to open the tasks form but I couldn't find a way to pass the projectID to only load records related to that project. I couldn't also find a good documentation for the Args().
The question is, how can I open Form2 and display only records related to the projectID from Form1?, also I want to be able to add new records to Form2 under the same projectID (not just a view).
Update
I was able to apply the filter with this code:
odoc2 = thiscomponent
FormModel = odoc2.drawpage.forms.getbyindex(0)
FormModel.Filter =("Tasks.projectID = " & ProjID)
FormModel.ApplyFilter = True
FormModel.reload()
However, since I am running it from the same Sub that opens Form2 it get applied to Form1 (which called the Sub). How can I get it to work on Form2 instead?
Your question provided most of the answer, which only needed some exploring with dbg_methods. The object variable FormModel2 in example below is what you are looking for:
frm_container = ThisDatabaseDocument.FormDocuments.getByName("Form2")
frm_container.open
FormModel2 = frm_container.component.getDrawPage.getforms.getbyindex(0)
FormModel2.Filter [....]
This works when run from "Form1".
Alternatively, you could permanently store the value that is supposed to be the subject of the filter in a separate table/row.
Hi guys i have a simple program that has 6 domain classes. Person, address, account, vehicle..etc. Each class has its own controller and views. My question is can i create another domain class to display ALL of the data from these classes. Person.gsp will only display Person data, Address.gsp only shows address data etc. I would like a class and gsp that will display ALL the above
Thanks
Yes, as it shows in the documentation, you can create a controller which returns all the data in the model to the view (edited to more fit your question):
class AllDataController {
List people
List addresses
def list() {
people = Person.list()
addresses = Address.list()
}
}
As the docs say:
If no explicit model is returned the controller's properties will be used as the model
Or of course, you could just return a model containing all the data you want available to the view
In your Person.gsp view, you can have something like this when showing the person data:
${person.address.text}
This is assuming that in your Address domain, you have a String called text. If you want this view to not be in person.gsp and be somewhere else, just pass all the Person records to your view, and use the person.address relation to show them both.
I'm having the strangest problem with a controller in a Grails project. I am trying to do a simple update of a domain object. Here is a simplified version of the controller
def updateRecord = {
def foundHVT = Process.get(params.hvt)
foundHVT.summaryBy = params.summaryBy
foundHVT.catalogBy = params.catalogBy
foundHVT.editBy = params.editBy
foundHVT.produceBy = params.produceBy
foundHVT.correctedBy = params.correctedBy
// a bunch more of these
foundHVT.save(flush: true);
redirect (action:resource, id: params.hvt)
}
If I run the a new instance of the application of and use this controller to update an object, it doesn't work, the object doesn't save. It will look fine within the controller. I can, for example, re-query the object and the changes are there, post save.
Now here's where it gets weird. If i use the preset scaffold edit controller and update/save an domain object -- and then switch back to this "updateRecord" controller it works FINE until i shut down the server it is working on?!?
I realize I am missing something very basic, but I can't find what it is. Any guidance would be most graciously appreciated.
DM
As HVGOTCODES noted Grails Clean seems to have fixed whatever weirdness was going on with this controller.
try putting a "def scaffold=true" in your controller if it does not already have the normal entry points.
Probably scaffolding save fills some field that you don't.
Possible problems:
Do check save() result and render foundHVT.errors the way Grails does. Add failOnError: true parameter to save() or just check foundHVT.hasErrors(). Look at foundHVT.errors.allErrors for validation problems.
Why not foundHVT.properties = params?
What is there is no foundHVT?
i have this code in my membership service class (taken from the asp.net-mvc sample app)
public MembershipUserCollection GetUnapprovedUsers()
{
MembershipUserCollection users = Membership.GetAllUsers();
MembershipUserCollection unapprovedUsers = new MembershipUserCollection();
foreach (MembershipUser u in users)
{
if (!u.IsApproved)
{
unapprovedUsers.Add(u);
}
}
return unapprovedUsers;
}
i now need a view to show this list of information and allow someone to approve them which will go back to the controller and set the IsApproved property to true.
Create a view which will generate a form containing label and checkbox for each member of the collection. You need to be able to get from the id of the checkbox to the user.
In the HTTP.POST Action method, iterate through the submitted fields looking for set checkboxes, when you find one set the corresponding user to approved.
Obviously the form can display arbitrary details for each user.
To use the inbuilt control helpers takes a bit more effort because you don't have a fixed size model to work with. To achieve something similar I:
Used a non-strongly typed view
populated ViewData["ids"] with IEnumerable<IdType> (which the view would loop over)
For each entry populated ViewData["field" + id] for each field I was displaying in the entity
In the view looped over the ids using ViewData["ids"] to call the HTML helpers with the id of the field.
(That was V1, in V2 I used model state so I could use the inbuilt validation error display support, but that doesn't really apply if you just want to select users.)
The POST processing was similar, repopulating the id list from the database and the looking up in the passed FormCollection.