I have a model class "Action" that get's extended by several other classes. I am new to django and assumed that if I called pre_save.connect(actionFunc, sender=Action) that actionFunc would get called anytime the save method in the Action class was called (including by any derived class).
My observation is that this function only gets triggered when the instance is a direct match of the Class type defined in Sender. Is there anyway to get this to recieve signals for all derived instances of Action as well?
No, you have to call the pre_save.connect as many number of times.
However, you can use python to get all the classes that extend the class of your interest, and loop over the pre_save connect statement.
Say, if the extended classes of the Action are all in a given file, you can do the following:
global_dict = globals().copy()
[el for el in global_dict.values() if getattr(el,'__base__',None)==Action]
one thing you can do is modify the signal sender in django so that instead of matching against a specific type it instead does
if isinstance(sender, filter):
send_signal()
(pseudocode)
Related
I have 4 classes, Customer, PickyCustomer, SegmentCustomer, and Delivery.
The Delivery class has a component within it called customer, like so:
class Delivery {
private:
Customer *customer;
Delivery(Customer *cust) // constructor
each of the Customer classes have a method called getAcceptable()
that is overrideable and is overridden within PickyCustomer and SegmentCustomer
From what I've read this is the correct way to call the overridden method from the Delivery class. By keeping the customer as a pointer it allows Delivery to call the child methods that override the base class.
But when trying to use unique_ptr I keep getting the error
no matching function for call to 'Delivery::Delivery(std::unique_ptr<Customer>*)'
when using the following bit of code to initialize
unique_ptr<Customer> cust1(new Customer("Name", "Home", 1000.0, 25.0, fileProduce));
shared_ptr<Delivery> cust1Delivery(new Delivery(cust1));
Can someone explain why I am getting this error, and show how I could fix this? Thanks.
Thanks to #paddy in the comments with the help! Using the get() function worked for me.
The below works for me.
unique_ptr<Delivery> cust1Delivery(new Delivery(cust1.get()));
I need to populate c++ model from a external source (for example USB). I have registered the model in main.cpp like this,
qmlRegisterType<HardwareDataModel>("org.example", 1, 0, "HardwareDataModel");
I need to change the private member of this HardwareDataModel class from the external source. Because I would like to change the the private data member of this model and fire signal to qml to change the UI. I got stuck how to proceed as I do not know how to populate those private data members. Do I need to instatiate HardwareDataModel in main.cpp? If yes, how to connect the instatiated HardwareDataModel object and one that is qmlRegisteredType (one shown above).
In kernel operations, an OpKernelConstruction pointer is given to the OpKernel constructor, for example
I would like to change some attributes in the context before passing it to the parent constructor.
For example, something like
explicit StreamQueueOp(OpKernelConstruction* context) :
TypedQueueOp(private_modifying_method(context))
But it appears in the description of OpKernelConstruction, that no modifying method exists. Is there a way to modify it?
EDIT:
I want to modify the attributes because I am attempting to make a FIFOQueue that pulls data from a database. I only want the user to have to specify the data stream id and then the queue would hit the database for the shape and type of the data. As such, I want to modify the context to add the shape and type info after I get it from the DB, but before I pass the context onto the base class. The base class makes use of shape and type, so I need to make sure it is in correspondence with the DB.
I have a custom grid control that inherits from TGrid called TFmGrid. This control was working fine in Rad Studio 10 Seattle Update One. I recently upgraded to 10.1 Berlin and started noticing this error message showing up on my TFmGrid controls both when I run the application and in the designer:
A descendant of TStyledPresentationProxy has not been registered for class TFmGrid. Maybe it is necessary to add the FMX.Grid.Style module to the uses section
The image below shows how the error message shows up on my grid controls:
I started by doing as the message suggests, and adding #include <FMX.Grid.Style.hpp> to the header file of my TFmGrid control, however this seems to have done nothing.
So as far as trying to register a decendant of TStyledPresentationProxy I am not exactly sure where to start. I found this documentation about a method which:
Attempts to register the presentation proxy class with the specified name or the specified combination of control class and control type.
So I assume I need to use this method or at least something similar, but I don't understand how I am supposed to go about calling this method.
But then that brings up the question of WHERE do I call this code?
My custom control has a method in its namespace called Register() which I believe was autogenerated by the IDE when the control was created:
namespace Fmgridu
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TFmGrid)};
RegisterComponents(L"Kalos FM Controls", classes, 0);
}
}
Do I need to call something in there to register a decendant of TStyledPresentationProxy? What is the proper way to go about this?
Just override virtual method DefinePresentationName in you TfmGrid and return name of presentation name for grid:
function TfmGrid.DefinePresentationName: string;
begin
Result := 'Grid-' + GetPresentationSuffix;
end;
Fm registers presentation by string name and uses class name for it, so if you create new component (based on existed) you automatically change classname, so system cannot find presentation for you. There are two solution:
Said that you will use presentation from TGrid (DefinePresentationName)
Register existed presentation for you class (look at the initialization section of FMX.Grid.Style.pas)
P.S. Year ago i wrote article about it in common eNew approach of development of FireMonkey control “Control – Model – Presentation”. Part 1 I hope it will help you
It's simple :
Just put "StyleBook" component to your form
I had the same issue with a test component I was developing.
Complementing Yaroslav Brovin's speech, I solved the problem by adding the class register in the initialization and finalization clauses at the end of the unit, like this:
initialization
TPresentationProxyFactory.Current.Register(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
finalization
TPresentationProxyFactory.Current.Unregister(<COMPONENT CLASSNAME HERE>, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
In my case looks like this:
initialization
TPresentationProxyFactory.Current.Register(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
finalization
TPresentationProxyFactory.Current.Unregister(TSGrid, TControlType.Styled, TStyledPresentationProxy<TStyledGrid>);
PS: Don't forget to declare the FMX.Presentation.Factory,
FMX.Presentation.Style and FMX.Grid.Style units in the uses clause
The following is an API reference for a method in "QmlDocument" class(Blackberry10).
Builder create (const QString &qmlAsset, boolautoLoad )
Creates and returns a builder for constructing a QmlDocument instance
with a parent object and an asset name to load the document from.
Parameters qmlAsset The QML asset name load the document from,
specified relative to the assets root. autoLoad if true the document
is automatic loaded, otherwise it is required to call load function
explicitly. The default is true . Since: BlackBerry 10.0.0
Now what is exactly meant by a "Builder" here. What is its purpose? what is the difference of creating an object from QmlDocument class with "new" keyword, and creating the object with the method defined above?
Builders are usually classes defined locally to the associated class (ie QmlDocument::Builder) that allow chaning of methods with operator . () in a way similar to that done with iostreams and operator << (). What it gets you is a more readable way of createing objects (and potentially their childre) in one statment rather than creating with a new operator and a number of function calls. A better example than QmlDocument might be the Container class:
Container *container1 = Container::create()
.preferredSize(200, 200)
.background(Color::Blue);
This creates a new Container, sets the preferred size and background color. The implementations details are hidden. Somewhat simmilar to an opaque type in C.