I want to use user firstname and lastname as a fullname in combo / listbox. Is it possible to define it on jdl or entity?
My solution:
Adding getFullName function to UserDTO and using it in entity json file or jdl.
Related
I had tried to define my id field as string and initialAutoIncrement field as 'E-100'. I am using MySQL.
SelectedFields is the list of the fields having API Name and itr the iterative variable and similarly rec is the iterator variable for the records So whenever I am using {!itr}
in the facet then it will print API name and If do not use facet then it will print label of the fields how to fix this??
<apex:repeat value="{!selectedFields}" var="itr">
<apex:column value="{!rec[itr]}">
<apex:facet name="header">
<apex:commandLink action="{!sortByColumn}" reRender="recPage">{!itr}
<apex:param name="Names" value="{!itr}" assignTo="{!sortingValues}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
Can you use $SobjectType to get the field label, something like {!$ObjectType.Account.fields[itr].label}?
Alternatively in apex build a Map<String, String> where key is the api name and value is the label. Or you can even iterate over list of field tokens, not strings. sObject class supports a dynamic get with field token as param so same trick should work in VF and you can get label out of a token too.
Yeah! {!$ObjectType.Account.fields[itr].label} It is the way to get the Label from the API name of Objects and For the dynamic objects. We can use this {!$ObjectType[sObject].fields[itr].label} as it will take out the label from the API names.
I have a model form similar to the one below:
class BookSearchForm(ModelForm):
class Meta:
model = Book
fields = ['publisher', 'authors', 'category'
How to override fields name attribute in the above model form?
I tried this, but it did not work:
class BookSearchForm(ModelForm):
class Meta:
model = Book
fields = ['publisher', 'authors', 'category'
widgets = {
'publisher': forms.SelectMultiple(attrs={'name': 'pub'}),
'authors': forms.SelectMultiple(attrs={'name': 'aut'}),
'category': forms.SelectMultiple(attrs={'name': 'cat'}),
}
you don't want to change the name of a field in the forms, django needs that to collect data for that field if you don't provide db_column as the name of the db column. what you can do with the first option, if you want the user to see publisher or some other name, in the models, add a verbose_name and then for the actual name you can declare the field however you want. Your code could look like this
pub = models.WhateverField(verbose_name='what i want you to see')
now when you do {{form.pub.label)}}, 'what i want you to see' is displayed in the html. Of course, don't forget to add the actual input in you template, {{form.pub}}. This way, you don't add anything extra in the form to display a user friendly name. I've posted this as an answer as i ran out of characters for a commment.
class Country(Models.Model):
code = models.CharField(max_length=50)
name = models.CharField(max_length=500)
class Meta:
unique_together = (('code', 'name'),)
db_table = 'md_country'
class UserSettings(models.Model):
...
default_countries = models.ManyToManyField(Country, db_table='user_default_countries', related_name='default_countries')
I have two models inside django models, what im trying is when i add Country models to default_countries i want to preserve order. Currently when i append manytomany field django automatically sort by Country name (alphabetical order)
I have this code
# iterate one by one to preserve fetching order
country_models = [Country.objects.get(id=_id) for _id in request.data[default_countries]]
user_settings.default_countries.clear()
for c in country_models:
user_settings.default_countries.add(c)
After this when i inspect user_settings.default_countries i have ordered countries by name in alphabetical order.
I want to preserve when adding element. If i want to add France and Australia and i order the list like that i on the end when i pull data from db i want it to be ordered like that. Now on this example i have Australia then France.
EDIT:
I checked the database and when inserting the data, it insert in right order
For example if i want France(73) then Australia(13), France has smaller id so its inserted first. There is a problem with django when pulling the data from database.
So as I understand correct you want to sort by insert order:
someSetting = UserSettings.objects.first()
countries = someSetting.default_countries.order_by('id')
I found the workaround.
Firstly i defined new property inside model where default_countries is.
#property
def ordered_default_countries(self):
return self.default_countries.all().order_by('-id')
Then in serializer where i serialize this field i just pointed default_countries field to ordered_default_countries.
Is there any easy way to create a view with all available fields from a form?
I have a form with over 100 fields and to create a view with all fields will take too much time. The aim is to export the data once it's in the view.
You can create View by using NotesDatabase.CreateView method, and create columns to this View by using NotesView.CreateColumn. The list of all fields in Form you can get from NotesForm.Fields property. The Form itself you can get from NotesDatabase.GetForm method.
Here is example:
Dim ses As New NotesSession
Dim db As NotesDatabase
Dim form As NotesForm
Dim view As NotesView
Set db = ses.CurrentDatabase
formName$ = "YourFormName"
Set form = db.GetForm(formName$)
Set view = db.CreateView(formName$ & "Fields", {Form = "} & formName$ & {"})
Forall field In form.Fields
Call view.CreateColumn(, field, field)
End Forall
You could open a document created with the form and iterate thorugh the NotesItems. There you can get the field names.
The code could looks something like this:
Dim field List As String
Forall i in doc.Items
field(i.Name) = i.Text
End Forall
You now have a list containing the text representation of the field as value and the name of the field as the list tag.
Or you could do this on each document and export all the values like that. Creating a view with 100 columns would create a huge view index. Not a great idea.
Maybe could you use
ReadViewEntries
Use this command to access view data in XML form without appearance attributes such as fonts, list separators, date formats, HTML settings, view templates and frame redirections.
Syntax:
http://Host/Database/ViewName?ReadViewEntries
Link: http://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/